asp.net-mvc-4

Redirect after Session Timeout in MVC Action Filter

馋奶兔 提交于 2021-01-29 08:02:18
问题 I have to redirect to home page after session timeout in mvc 5 application. I am using following code : public class SessionExpireAttribute : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { var currentEnvironment = EnvironmentUtility.GetSession().Get<Environment>(); if (currentEnvironment == null) { filterContext.Result = new RedirectResult("~/Home/Index"); } base.OnActionExecuting(filterContext); } } In the controller, I have below code

Can't create .edmx file for postgresql use entityframework + npgsql

佐手、 提交于 2021-01-29 03:35:34
问题 I want to create ADO.NET entity data model - database first (.edmx file) with EntityFramework6.Npgsql but it's error. I have installed: - EntityFramework6.Npgsql (version 6.3 newest) - Npgsql (version 4.1.1 newest) - EntityFramework (version 6.3 newest) I created it before, but I don't know why now! Please help me.... 回答1: This is a known issue that is already tracked on github In the meantime for those having issues with the latest version of the VSIX (4.1.1.2), please downgrade back to 4.0

Get post data with unknown number of variables in ASP MVC

元气小坏坏 提交于 2021-01-28 11:43:00
问题 I have an entity with a variable set of attributes named ExtendedProperty , these have a key and a value. In my html razor view, I have this: @if (properties.Count > 0) { <fieldset> <legend>Extended Properties</legend> <table> @foreach (var prop in properties) { <tr> <td> <label for="Property-@prop.Name">@prop.Name</label> </td> <td> <input type="text" name="Property-@prop.Name" value="@prop.Value"/> </td> </tr> } </table> </fieldset> } How can I access this data on my controller once the

AntiXSS JavaScriptEncode gets HTML encoded?

时间秒杀一切 提交于 2021-01-28 05:30:12
问题 I've just started using AntiXSS (4.3.0), mostly to use @Encoder.JavaScriptEncode as described here. I installed AntiXSS from Nuget, then added encoderType="Microsoft.Security.Application.AntiXssEncoder, AntiXssLibrary" to <httpRuntime in my Web.config. In my view, I have the following line (within <script> tags): var userId = @Encoder.JavaScriptEncode(User.Identity.GetUserId()); Which I would expect to output var userId = 'user-id'; but instead outputs: var userId = 'user-id'; I assume this

How to check if a RadioButton is checked in Razor?

a 夏天 提交于 2021-01-28 04:03:11
问题 I have the following lines of code in a cshtml file, <div class="YesNo"> <label><input type="radio" name="YesNo_@pNum" value="Yes" />@yesLabel</label> <label><input type="radio" name="YesNo_@pNum" value="No" checked />@noLabel</label> </div> How can I use an if condition in Razor to check if "Yes" radiobutton is checked and then only display a certain label? I have these 2 properties in my model, public string YesLabel { get { return COff.YesLabel ?? "Yes"; } } public string NoLabel { get {

automapper project into a larger object

左心房为你撑大大i 提交于 2021-01-28 03:56:21
问题 With Automapper, is it possible to project a smaller object onto a larger one? For example, a controller accepts data as a ViewModel instance. I would then need to create a record in a database. So I would project this View Model onto a Domain Model. Once I have a Domain Model instance populated with View Model data I would then manually populate the additional fields in the Domain Model before storing data in the database. Is it possible to do so? Thanks. 回答1: Yes this is perfectly possible.

automapper project into a larger object

廉价感情. 提交于 2021-01-28 03:30:39
问题 With Automapper, is it possible to project a smaller object onto a larger one? For example, a controller accepts data as a ViewModel instance. I would then need to create a record in a database. So I would project this View Model onto a Domain Model. Once I have a Domain Model instance populated with View Model data I would then manually populate the additional fields in the Domain Model before storing data in the database. Is it possible to do so? Thanks. 回答1: Yes this is perfectly possible.

How To add a row to table by ajax actionlink

丶灬走出姿态 提交于 2021-01-28 02:26:09
问题 I 'm a newbie of MVC4, i got a problem. When I want to add a row into a table in ajax, it doesn't seem like what i want. Here my code <table> <thead> <tr> <th>Tên học sinh </th> <th>Giáo lý viên </th> <th>Năm Học</th> <th>Điểm TB Học Kỳ 1 </th> <th>Điểm TB Học Kỳ 2 </th> <th>Điểm Tổng Kết Năm Học </th> <th>Lớp </th> </tr> </thead> @using (Html.BeginForm()) { @Html.AntiForgeryToken() @Html.ValidationSummary(true) <fieldset class="form-horizontal"> <legend></legend> <tbody> <tr> <td> @Html

Mixing Razor and Javascript: Assigning a number from Model to a Javascript variable in a view

一个人想着一个人 提交于 2021-01-28 01:04:46
问题 I'm having difficulties to assign just a basic number from Model to a Javascript variable via Razor. All that I came up with was the code below, which works, but is rather ugly as I have to convert the string value into a number. Is there any other way to just get it right away in the numeric format without any conversions? var MyNumber = parseInt('@Model.MyNumber'); 回答1: You should be able to do this: var MyNumber = @Model.MyNumber; or better, use the brackets to make the Razor part explicit

MVC4 JSON.Net oob

时间秒杀一切 提交于 2021-01-27 14:15:24
问题 I have read a few pieces of conflicting information regarding MVC 4's out-of-the-box support for JSON.NET I gathered that MVC is serializing JSON by default using JSON.NET now, however I still have the tell-tale MS date format in my JSON output. Is there any bootstrapping that still needs to be done? Example action: // // GET: /Test/ [HttpGet] public JsonResult Test() { return Json(new {date = DateTime.Now}, JsonRequestBehavior.AllowGet); } results in: { "date": "/Date(1355399663508)/" } 回答1: