model-binding

ASP.Net MVC Model binding a [Serializable] class

…衆ロ難τιáo~ 提交于 2019-12-22 10:59:16
问题 I have this class [Serializable] public class MyObject { // properties omitted } And this WebAPI controller method: [HttpPost] [ResponseType(typeof(string))] public IHttpActionResult SetMyObject(MyObject o) { // process object } But it fails to model bind to the MyObject class. The object o in the controller method is completely empty, every property is default (so mostly null). Turns out this is because of the [Serializable] annotation on MyObject. Removing that makes model binding work

CheckBoxList multiple selections: how to model bind back and get all selections?

橙三吉。 提交于 2019-12-22 10:53:21
问题 This code: Html.CheckBoxList(ViewData.TemplateInfo.HtmlFieldPrefix, myList) Produces this mark-up: <ul><li><input name="Header.h_dist_cd" type="checkbox" value="BD" /> <span>BD - Dist BD Name</span></li> <li><input name="Header.h_dist_cd" type="checkbox" value="SS" /> <span>SS - Dist SS Name</span></li> <li><input name="Header.h_dist_cd" type="checkbox" value="DS" /> <span>DS - Dist DS Name</span></li> <li><input name="Header.h_dist_cd" type="checkbox" value="SW" /> <span>SW - Dist SW Name <

How to get DataAnnotations working in asp.net 4.5 WebForms?

一世执手 提交于 2019-12-22 09:31:02
问题 I'm using .net 4.5 WebForms with Model Binding and Entity Framework 5. Part of my webform: <asp:ListView ID="MenteeModuleList" ItemPlaceholderID="itemPlaceHolder" OnCallingDataMethods="MenteeModuleList_CallingDataMethods" ItemType="PFA_Mentorship.BLL.MenteeModuleBL+MenteeModuleGrid" DataKeyNames="MenteeModuleID" SelectMethod="GetMenteeModulesGrid" InsertItemPosition="LastItem" InsertMethod="InsertMenteeModule" runat="server"> <LayoutTemplate> <table runat="server"> <tr runat="server"> <th id=

Web API action parameter is intermittently null

落花浮王杯 提交于 2019-12-22 08:38:11
问题 Related question: Web API ApiController PUT and POST methods receive null parameters intermittently Background While load testing an existing Web API project I noticed a lot of null reference exceptions as a result of a parameter being null when posting to an action. The cause seems to be a custom message handler registered to log requests while running in dev environments. Removing this handler resolves the issue. I understand that in Web API I can only read the request body once and that

Asp.Net MVC Dynamic Model Binding Prefix

折月煮酒 提交于 2019-12-22 08:24:53
问题 Is there any way of changing the binding prefix with a value which comes from the request parameters? I have many nested search popups, and all of them shares the same ViewModel. I can add a binding prefix to all the fields when requesting for the Search filters, but i don't know how can i make the [Bind(Prefix = "")] to work with values coming from the request parameters. // get the search filters with the bindingPrefix we need public ActionResult Search(string bindingPrefix) { ViewData

Model binding the sort field from KendoUI Grid

*爱你&永不变心* 提交于 2019-12-22 08:08:06
问题 I'm using KendoUI Grid to show data. I have server paging working like a charm. The each page change in the kendo grid is a new ajax request to the server and the server returns the correct page of data. I am now trying to do server-side sorting, but I'm having trouble getting model binding to bind to the sort values. This is what the request from the Kendo Grid looks like: My action method looks like this: public JsonResult GetReports(int pageSize, int skip, List<KendoSort> sort) { // sort

ASP.NET MVC 5 Model-Binding Edit View

狂风中的少年 提交于 2019-12-22 05:25:11
问题 I cannot come up with a solution to a problem that's best described verbally and with a little code. I am using VS 2013, MVC 5, and EF6 code-first; I am also using the MvcControllerWithContext scaffold, which generates a controller and views that support CRUD operations. Simply, I have a simple model that contains a CreatedDate value: public class WarrantyModel { [Key] public int Id { get; set; } public string Description { get; set; } DateTime CreatedDate { get; set; } DateTime

ASP.NET MVC ModelBinder bug: Binding request variable “id” to Model's property “Id”

强颜欢笑 提交于 2019-12-22 01:34:25
问题 I am using MVC 3 final RTM. Given This route: context.MapRoute( "Blog_Posts", "Blog/Posts/{id}/{slug}", new { controller = "Posts", action = "Index", slug = UrlParameter.Optional } ); And on a post's page, e.g. /blog/posts/2/some-slug I bind a partial view with a Comment model: @Html.Partial("_CommentEditor", new Comment()) And Comment has a public int Id {get; set;} . And in the partial view, I have this: @Html.HiddenFor(comment => comment.Id) Why does it display this? <input type="hidden"

How can I do model binding and data display at the same time using the same model.list?

≯℡__Kan透↙ 提交于 2019-12-22 01:28:19
问题 I have a code similar to this: My View @model MyCode.Models.RemarksModel foreach (var row in Model.List) { <tr> <td align="center"><font class="font_table_content">@row.Id</font></td> <td align="center"><font class="font_table_content">@row.Full_Name</font></td> <td align="center"><font class="font_table_content">@Html.TextBox("row.Remarks")</font></td> } My Model public class RemarksModel { public IList<UserRemarks> List { get; set; } } My UserRemarks Object public class UserRemarks { public

Implementing ASP.NET MVC 3 Interface Model Binding (with ViewModel)

最后都变了- 提交于 2019-12-21 23:18:09
问题 I just learning ASP.NET MVC 3 and I'm a bit confused on how I can implement something like what is shown in this link: http://www.codethinked.com/easy-and-safe-model-binding-in-aspnet-mvc Why I'm confused is most likely based on my ignorance in the subject. In the example on the page linked above, I see Justin is using a ViewModel that directly contains properties of his "Person" object. What I want to do is similar, but I want to have a ViewModel actually contain the domain class, which is