model-binding

Is model binding possible without mvc?

你说的曾经没有我的故事 提交于 2019-12-30 11:56:06
问题 Say I have a Dictionary<string, string> and I want to update an object with the values from the dictionary, just like model binding in MVC... how would you do that without MVC? 回答1: You could use the DefaultModelBinder to achieve this but you will need to reference the System.Web.Mvc assembly to your project. Here's an example: using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Globalization; using System.Linq; using System.Web.Mvc;

Underscore string model binder

可紊 提交于 2019-12-30 07:05:16
问题 I was under the impression that when binding to a complex model, all public properties were processed and a match binding attempted for each. I'm trying to resolve a variable naming problem so that a model class Model { public string Foo {get;set;} public string FooBar {get;set;} } works nicely with a query string like ?foo=foo&foo_bar=foo_bar Is there a better way than with a custom model binder? In any case, mine doesn't work. FooBar is simply skipped. public class StringModelBinder :

Data loss when passing raw HTML from View to Controller in POST request — XSS-safety & information loss

不羁岁月 提交于 2019-12-29 09:36:13
问题 Preamble My use-case includes a front-end WYSIWYG editor. Taking user input in HTML5/CSS format from the CSHTML Front-End View. Receiving the input in the Backend Controller's action via POST request. And finally doing fancy Database stuff with it. Sounds pretty easy. Using this beast of an editor, it's very straightforward and customizable. View WYSIWYG editor textarea nested within a form to send editor's raw HTML data using POST <form class="form" asp-controller="CreationController" asp

Dictionary<short, Dictionary<EnFunction, bool>> model binding not work

删除回忆录丶 提交于 2019-12-29 09:24:08
问题 I could not bind the model to Controller. Please give me any advice. Model,controller and view classes are below. When model is submmited, dictionary property equals to null. public class GroupRights //model { public List<DtoGrup> groups { get; set; } public Dictionary<short, Dictionary<EnFunction, bool>> groupRights { get; set; } // group function HasPermission } public enum EnFunction { LPDU_login, LPDU_changePassword, LPDU_transitList, LPDU_PosEventList, .... } Controller public

Deserialization / model binding in MVC4 webapi does not work with arrays

半腔热情 提交于 2019-12-29 07:53:04
问题 I'm using the new WebApi which is part of MVC4 beta. I have the following class: public class Voucher { public string Id { get; set; } public string TableId { get; set; } public Product[] Products { get; set; } } My controller looks like this: public class VouchersController : ApiController { public Voucher PostVoucher(Voucher voucher) { //.... } } On the client side I serialize the data using an XmlSerializer . The output looks like expected and the Products array is serialized. If I post

Finding custom attributes on view model properties when model binding

依然范特西╮ 提交于 2019-12-29 06:39:15
问题 I've found a lot of information on implementing a custom model binder for validation purposes but I haven't seen much about what I'm attempting to do. I want to be able to manipulate the values that the model binder is going to set based on attributes on the property in the view model. For instance: public class FooViewModel : ViewModel { [AddBar] public string Name { get; set; } } AddBar is just public class AddBarAttribute : System.Attribute { } I've not been able to find a clean way to

ASP.NET MVC - drop down list selection - partial views and model binding

倖福魔咒の 提交于 2019-12-28 13:56:20
问题 I'm fairly new to ASP.NET MVC and am trying to work out the best way to do this. It's probably simple but I just want to do things correctly so I thought I'd ask. Lets say I have a model that is this: Task - Id, Description, AssignedStaffMember StaffMember - Id, FirstName, LastName and in my view I want to create a new task. I make a strongly typed Razor view, and can use EditorFor to create textboxes for Description but what about AssignedStaffMember? I want a drop down list of all current

ASP.NET MVC - drop down list selection - partial views and model binding

做~自己de王妃 提交于 2019-12-28 13:56:08
问题 I'm fairly new to ASP.NET MVC and am trying to work out the best way to do this. It's probably simple but I just want to do things correctly so I thought I'd ask. Lets say I have a model that is this: Task - Id, Description, AssignedStaffMember StaffMember - Id, FirstName, LastName and in my view I want to create a new task. I make a strongly typed Razor view, and can use EditorFor to create textboxes for Description but what about AssignedStaffMember? I want a drop down list of all current

Asp.Net mvc 5 - How can I pass a complex object as route value in Html.ActionLink() so default model binder can map it?

一世执手 提交于 2019-12-28 06:31:25
问题 I have an object containing searching, sorting and paging parameters as well as an id of a record to be edited. I'd like to pass this object into Html.ActionLink() as a route value object, so that the resulting query string will be correctly mapped by the default model binder into the Edit action's parameter, which is an EditViewModel. The idea is that after the Edit action completes, it can redirect back to the Index and maintain the same paging/sorting position, in the same data set, and

Asp.Net mvc 5 - How can I pass a complex object as route value in Html.ActionLink() so default model binder can map it?

≡放荡痞女 提交于 2019-12-28 06:31:07
问题 I have an object containing searching, sorting and paging parameters as well as an id of a record to be edited. I'd like to pass this object into Html.ActionLink() as a route value object, so that the resulting query string will be correctly mapped by the default model binder into the Edit action's parameter, which is an EditViewModel. The idea is that after the Edit action completes, it can redirect back to the Index and maintain the same paging/sorting position, in the same data set, and