model-binding

How do I Bind a Collection (IEnumerable) of a custom type?

杀马特。学长 韩版系。学妹 提交于 2019-12-04 20:57:14
问题 I have the following Action to display a form with 3 items : [HttpGet] public ActionResult ReferAFriend() { List<ReferAFriendModel> friends = new List<ReferAFriendModel>(); ReferAFriendModel f1 = new ReferAFriendModel(); ReferAFriendModel f2 = new ReferAFriendModel(); ReferAFriendModel f3 = new ReferAFriendModel(); friends.Add(f1); friends.Add(f2); friends.Add(f3); return View(friends); } and then a Post action [HttpPost] public ActionResult ReferAFriend(IEnumerable<ReferAFriendModel> friends

asp.net mvc checkbox/radiobutton matrix model-binding

放肆的年华 提交于 2019-12-04 19:38:10
I have a dynamic forms with checkbox/radio-button lists & matrices: Following code renders checkbox list: @foreach (var sq in Model.SubQuestions) { <label> <input type="hidden" name="answerResult.index" value="@sq.Id" /> <input type="checkbox" name="answerResult[@sq.Id].SubQuestionId" value="@sq.Id" /> @sq.Label.Name </label> } radio-button list: <input type="hidden" name="answerResult.index" value="@Model.Id" /> @foreach (var sq in Model.SubQuestions) { <label> <input type="radio" name="answerResult[@Model.Id].SubQuestionId" value="@sq.Id" /> @sq.Label.Name </label> } My POST-action in

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

两盒软妹~` 提交于 2019-12-04 18:43:37
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 in my case Company, rather than Person. I'm having the Company class itself implement the ViewModel

How to bind a Knockout js model to a wizard style UI

馋奶兔 提交于 2019-12-04 18:43:27
问题 I am using Knockout js. I have a view model that contains an array of objects and I want to allow the user to edit one of the objects using a wizard style interface. The issue I have is the wizard will show different steps depending on what choices are made . For instance: If the user selects 'Yes' on step 1 then I display step 2a If the user selects 'No' on step 1 then I display step 2b (ie. a different dialog form) This goes on so that the paths through the wizard are not linear. My

Polymorphic custom model binder not populating model w/ values

空扰寡人 提交于 2019-12-04 18:42:40
I have a custom model binder that I'm using to return the appropriate model sub-type based on a hidden value containing the original type. For example, in my view (EditorTemplate) I have: @model MyWebApp.Models.TruckModel @Html.Hidden("ModelType", Model.GetType()) @Html.EditorFor(m => m.CabSize) Then, in my custom model binder, I have: protected override object CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType) { var typeValue = bindingContext.ValueProvider .GetValue(bindingContext.ModelName + ".ModelType"); var type = Type.GetType((string

MVC.Net binding complex models?

ε祈祈猫儿з 提交于 2019-12-04 18:18:44
I have the following code, with an existing customer. I need to create a form that created an Order, and pass it to my Controller. I tried changing my model type on that page to Order instead of Customer, but then I'm gonna have to pass the Order object as well, or at least the OrderId. Models public class Customer { public int Id { set; get; } public string FirstName { set; get; } public string LastName { set; get; } public List<Order> Orders { get; set;} } public class Order { public int Id { set; get; } public string ItemName { set; get; } public DateTime SomeDate { set; get; } } Controller

Custom model binder with inheritance using Web API and RavenDB

本小妞迷上赌 提交于 2019-12-04 17:37:25
I'm developing a simple web app where I need to bind all types implementing and interface of a specific type. My interface has one single property like this public interface IContent { string Id { get;set; } } a common class using this interface would look like this public class Article : IContent { public string Id { get;set; } public string Heading { get;set; } } to be clean here the article class is just one of many different classes implementing IContent so therefor I need a generic way of storing and updating these types. So in my controller I have the put method like this public void Put

Gwt editor with not only getter/setter bean class

て烟熏妆下的殇ゞ 提交于 2019-12-04 15:54:53
Lets say I have form build in GWT, an UI-Binder, which implements Editor interface (com.google.gwt.editor.client.Editor) with two date fields (date from and to). Bean class is expected to have members: Date fromDate; // with getter and setter Date toDate; // with getter and setter And okay, while having bean class defined as written, there is no problem, but just after I add something like this: public boolean hasFromDate() { return fromDate != null; } I got compilation error (for example for fromDate): [ERROR] Line 17: The method hasFromDate() is undefined for the type Date [ERROR] Line 20:

What is the equivalent of MVC's DefaultModelBinder in ASP.net Web API?

◇◆丶佛笑我妖孽 提交于 2019-12-04 15:42:33
问题 I want to create a custom model binder in ASP.Net Web API. There are plenty of resources on how to do this from scratch, but I want to leverage existing functionality. I have looked around in the source on codeplex and can see plenty of modelbinders in there but most are sealed... and even then I can't work out which one would be used in which situations. Here is my api method header: public async Task<HttpResponseMessage> Post(long appId, [FromBody]Field field) What I want to do is basically

ModelMetaData, Custom Class Attributes and an indescribable question

感情迁移 提交于 2019-12-04 13:29:41
问题 What I want to do seems so simple. In my index.cshtml I want to display the WizardStepAttribute Value So, a user will see at the top of each page, Step 1: Enter User Information I have a ViewModel called WizardViewModel . This ViewModel has a property that is IList<IStepViewModel> Steps each "step" implements the Interface IStepViewModel, which is an empty interface. I have a view called Index.cshtml. This view displays EditorFor() the current step. I have a custom ModelBinder, that binds the