model-binding

when passing a collection to EditorFor(), it generates invalid names for input elements

≡放荡痞女 提交于 2019-12-03 02:47:33
I have a BookCreateModel which consists of book's plane info such as Title, PublishYear & etc plus a collection of book Authors (complex type) : public class BookCreateModel { public string Title { get; set; } public int Year { get; set; } public IList<AuthorEntryModel> Authors { get; set; } } public class AuthorEntryModel { public string FirstName { get; set; } public string LastName { get; set; } } in CreateBook view I have used EditorFor helper : @Html.EditorFor(m => m.Authors, "AuthorSelector") Edit1: and AuthorSelector template is as below: <div class="ptr_authors_wrapper"> @for (int i =

Dynamic form and data binding with Spring MVC

走远了吗. 提交于 2019-12-03 02:35:45
In my Spring MVC application I need to implement a dynamic questionnaire form: I have N questions and for each I have 3 options. So in my page I'll have something like this: | Question 1 | 1 | 2 | 3 | | Question 2 | 1 | 2 | 3 | | Question 3 | 1 | 2 | 3 | | ... | 1 | 2 | 3 | | Question N | 1 | 2 | 3 | Questions are stored in a database and for the options I'll use radio buttons. I'll use a forEach tag to creare dynamic rows, but I don't know how to post data and handle ModelAttribute binding in this scenario... Which could be a good structure for my model attribute class? Is it possible to use

Bind Checkboxes to int array/enumerable in MVC

♀尐吖头ヾ 提交于 2019-12-03 01:44:56
@Html.CheckBox("orderNumbers", new { value = 1 }) @Html.CheckBox("orderNumbers", new { value = 2 }) @Html.CheckBox("orderNumbers", new { value = 3 }) @Html.CheckBox("orderNumbers", new { value = 4 }) @Html.CheckBox("orderNumbers", new { value = 5 }) [HttpPost] public ActionResult MarkAsCompleted(IEnumerable<int> orderNumbers) { } [HttpPost] public ActionResult MarkAsCompleted(IEnumerable<string> orderNumbers) { } If I use the first signature in my action method, I get an empty IEnumerable . If I use the second signature I do receive the values but I also receive a false value for the

Asp.net core model doesn't bind from form

久未见 提交于 2019-12-02 23:11:42
I catch post request from 3rd-side static page (generated by Adobe Muse) and handle it with MVC action. <form method="post" enctype="multipart/form-data"> <input type="text" name="Name"> ... </form> Routing for empty form action: app.UseMvc(routes => routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}")); But in according action I have model with every property is empty Action: [HttpPost] public void Index(EmailModel email) { Debug.WriteLine("Sending email"); } Model: public class EmailModel { public string Name { get; set; } public string Email { get; set; } public

MVC 3 doesn't bind nullable long

邮差的信 提交于 2019-12-02 22:19:47
I made a test website to debug an issue I'm having, and it appears that either I'm passing in the JSON data wrong or MVC just can't bind nullable longs. I'm using the latest MVC 3 release, of course. public class GetDataModel { public string TestString { get; set; } public long? TestLong { get; set; } public int? TestInt { get; set; } } [HttpPost] public ActionResult GetData(GetDataModel model) { // Do stuff } I'm posting a JSON string with the correct JSON content type: { "TestString":"test", "TestLong":12345, "TestInt":123 } The long isn't bound, it's always null. It works if I put the value

ASP.Net Web API custom model binding with x-www-form-urlencoded posted data - nothing seems to work

南笙酒味 提交于 2019-12-02 20:59:07
I am having a lot of trouble getting custom model binding to work when posting x-www-form-urlencoded data. I've tried every way I can think of and nothing seems to produce the desired result. Note when posting JSON data, my JsonConverters and so forth all work just fine. It's when I post as x-www-form-urlencoded that the system can't seem to figure out how to bind my model. My test case is that I'd like to bind a TimeZoneInfo object as part of my model. Here's my model binder: public class TimeZoneModelBinder : SystemizerModelBinder { protected override object BindModel(string attemptedValue,

C# WPF MVVM Binding not updating

点点圈 提交于 2019-12-02 17:38:17
问题 I'm trying to do simple binding using a converter to display count of elements inside observable collection that satisfy given enum, let's say A B C D. The code below works when I test it with my other project, but on the most basic project binding doesn't get updated. The exact same code works inside other project (really strange). How I'm doing the binding <Label Content="{Binding Source={x:Static viewmodels:TestViewModel.Instance}, Path=TestModels, Converter={StaticResource TestConverter},

C# WPF MVVM Binding not updating

China☆狼群 提交于 2019-12-02 12:35:52
I'm trying to do simple binding using a converter to display count of elements inside observable collection that satisfy given enum, let's say A B C D. The code below works when I test it with my other project, but on the most basic project binding doesn't get updated. The exact same code works inside other project (really strange). How I'm doing the binding <Label Content="{Binding Source={x:Static viewmodels:TestViewModel.Instance}, Path=TestModels, Converter={StaticResource TestConverter}, Mode=OneWay}"></Label> Converter class TestConverter : IValueConverter { public object Convert( object

MVC 3 - Model Binding a list in a table with each record being a column instead of row

独自空忆成欢 提交于 2019-12-02 12:24:44
问题 I can find various articles about how to model-bind a list of items in MVC 3, even from within a table, but in each example the rows represent a record in the list. The requirements for my view are that each record must be a column. I cannot get any of the tricks from the following articles working: http://blog.stevensanderson.com/2010/01/28/editing-a-variable-length-list-aspnet-mvc-2-style/ http://dotnetslackers.com/articles/aspnet/Understanding-ASP-NET-MVC-Model-Binding.aspx#s8-binding-with

Consume jQuery.serializeArray in ASP.NET MVC

僤鯓⒐⒋嵵緔 提交于 2019-12-02 10:39:45
问题 I post $('#myForm').serializeArray() to an ASP.NET MVC (2.0) action. serialized array looks as follows: filters[0][name] : gemcolor filters[0][value] : Yellow filters[1][name] : gemcolor filters[1][value] : Green filters[2][name] : jcOnly filters[2][value] : true someOtherData : abc I want to have that consumed in: public ActionResult GetData(Filter filter) class Filter { string someOtherData; bool jcOnly; List<string> gemcolor; } I can just dig through FormCollection , but I am looking for a