model-binding

ASP.Net Web API model binding not working like it does in MVC 3

老子叫甜甜 提交于 2019-12-03 22:13:37
I was under the impression that model binding in the ASP.Net Web API was supposed to support binding with the same minimum level of functionality supported by MVC. Take the following controller: public class WordsController : ApiController { private string[] _words = new [] { "apple", "ball", "cat", "dog" }; public IEnumerable<string> Get(SearchModel searchSearchModel) { return _words .Where(w => w.Contains(searchSearchModel.Search)) .Take(searchSearchModel.Max); } } public class SearchModel { public string Search { get; set; } public int Max { get; set; } } I'm requesting it with: http:/

Non sequential list binding not working

折月煮酒 提交于 2019-12-03 21:45:24
问题 As per this article I am trying to bind a list of non sequential items. View: <%using (Html.BeginForm("Products", "Home", FormMethod.Post)) { %> <input type="hidden" name="products.Index" value="cold" /> <input type="text" name="products[cold].Name" value="Beer" /> <input type="text" name="products[cold].Price" value="7.32" /> <input type="hidden" name="products.Index" value="123" /> <input type="text" name="products[123].Name" value="Chips" /> <input type="text" name="products[123].Price"

JTable setting model and preserve column formats (width, alignment, etc.)

三世轮回 提交于 2019-12-03 20:37:04
问题 This is a brain-cracking experience with JTable binding. Here's what I did. I created a JTable with columns set to a specified width, formatted it using renderers , and added some codes on it. But when i try to bind it to a model, all the columns were replaced by the fields of the model . Is there a way on how to correctly bind it? I'm avoiding loops because there are 100+ thousand records in the database. I'm trying to use other methods such as BeansBinding and EntityManager but I don't know

Percentage properties in MVC 3

巧了我就是萌 提交于 2019-12-03 17:35:24
问题 My application has many models, many of which contain percentage data. These are represented as decimal or decimal? structs in the model. However, not all properties with decimal structs are percentages. Some should be treated like regular decimals. The percentages need special attention: For display, they should use {0:P2} format. (I have this part working.) For editing, they should allow the same format as the display, i.e. "95" or "95%" or "95.00 %" all bind to a value of 0.95. I started

asp.net 4.5 webforms model binding : client side validation supported?

旧城冷巷雨未停 提交于 2019-12-03 16:44:02
I'm a huge fan of asp.net 4.5 webforms model binding using data annotations. ascx: <asp:FormView ItemType="Contact" runat="server" DefaultMode="Edit" SelectMethod="GetContact" UpdateMethod="SaveContact"> <EditItemTemplate> <asp:ValidationSummary runat="server" ID="valSum" /> Firstname: <asp:TextBox runat="server" ID="txtFirstname" Text='<%#: BindItem.Firstname %>' /> Lastname: <asp:TextBox runat="server" ID="txtLastname" Text='<%#: BindItem.Lastname %>' /> Email: <asp:TextBox runat="server" ID="txtEmail" Text='<%#: BindItem.Email %>' /> <asp:Button ID="Button1" runat="server" Text="Save"

HttpPostedFileBase not binding to model

一个人想着一个人 提交于 2019-12-03 15:50:15
问题 here is my ViewModel public class FaultTypeViewModel { [HiddenInput(DisplayValue = false)] public int TypeID { get; set; } [Required(ErrorMessageResourceType = typeof(AdministrationStrings), ErrorMessageResourceName = "FaultTypeNameRequired")] [Display(ResourceType = typeof(AdministrationStrings), Name = "FaultTypeName")] public string TypeName { get; set; } [Display(ResourceType = typeof(AdministrationStrings), Name = "FaultTypeDescription")] [DataType(DataType.MultilineText)] public string

CultureInfo issue with Modelbinding double in asp.net-mvc(2)

笑着哭i 提交于 2019-12-03 14:11:11
In my Jquery script I post two doubles using the browser's CultureInfo (en-UK) that uses the . as a fraction separator. My MVC app is running on a server with locale nl-BE using the , as a fraction separator. [AcceptVerbs(HttpVerbs.Post)] public JsonResult GetGridCell(double longitude, double latitude) { var cell = new GridCellViewModel { X = (int)Math.Round(longitude, 0), Y = (int)Math.Round(latitude, 0) }; return Json(cell); } The modelbinding fails because of the parsing issue. I think it would be best to have my javascript set to en-UK and the same for the modelbinding in my MVC app. But I

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

给你一囗甜甜゛ 提交于 2019-12-03 13:48:57
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) { if(ModelState.IsValid){ EDIT My View looks like this: @model IEnumerable<Models.ReferAFriendModel>

ASP.NET MVC5: Want to update several items in Collection with model binding

戏子无情 提交于 2019-12-03 13:29:23
So I have a Collection of User objects, which should be mass-editable (edit many users at the same time). I'm saving the user input to the database using Entity Framework. The collection the controller method gets from the form is null. Why? Also, is the BindAttribute possible to use with collections like in my code? View: @model IEnumerable<Domain.User> @using (Html.BeginForm("UpdateUsers", "Users")) { @Html.AntiForgeryToken() @Html.ValidationSummary(true) foreach (var item in Model) { @Html.HiddenFor(modelItem => item.Id) @Html.EditorFor(modelItem => item.FirstName) @Html

Backbone.js: avoid view→model→view double conversion

允我心安 提交于 2019-12-03 12:42:25
I’m trying to build this: When I edit field on the left it should update the one on the right and vice-versa. Editing a value in an input field causes the text cursor to jump at the end of it. Typing "2" in the fahrenheit field gets replaced with 1.999999999999, as you can see on the screenshot. This happens because of the double conversion: view’s Fº → model’s Cº → view’s Fº. How can I avoid that? Update: I want to know the elegant way of dealing with two-way bindings in MVC frameworks such as Backbone.js. MVC var Temperature = Backbone.Model.extend({ defaults: { celsius: 0 }, fahrenheit: