modelbinders

ASP.NET MVC 2 - ViewModel Prefix

走远了吗. 提交于 2020-01-01 04:37:32
问题 I want to use RenderPartial twice in my view with different models associated. The problem is that some properties are present in both models (nickname, password). They have no prefix, so even the id's or names are equal in the output. Now, if I have model errors for nickname or password, both fields get highlighted. Main View: <div> <% Html.RenderPartial("Register", Model.RegisterModel); %> </div> <div> <% Html.RenderPartial("Login", Model.LoginModel); %> </div> Login PartialView: <% using

ASP.NET MVC 2 - ViewModel Prefix

萝らか妹 提交于 2020-01-01 04:37:28
问题 I want to use RenderPartial twice in my view with different models associated. The problem is that some properties are present in both models (nickname, password). They have no prefix, so even the id's or names are equal in the output. Now, if I have model errors for nickname or password, both fields get highlighted. Main View: <div> <% Html.RenderPartial("Register", Model.RegisterModel); %> </div> <div> <% Html.RenderPartial("Login", Model.LoginModel); %> </div> Login PartialView: <% using

MVC3 ModelBinder for DynamicObject

牧云@^-^@ 提交于 2019-12-30 14:44:47
问题 I'm looking to see if there is a sample project, tutorial, contrib branch or anything like that that details implementing a custom ModelBinder for MVC3 to support objects inheriting from DynamicObject. I have an domain object that has a dynamic number of properties as defined by the database, and these can change at run time. To make using the object easier I've made my class implementation inherit from DynamicObject and am passing the model to the view via the [dynamic] keyword. All of the

ASP.NET MVC - Alternative for [Bind(Exclude = “Id”)]

会有一股神秘感。 提交于 2019-12-28 05:22:47
问题 Is there an alternative for [Bind(Exclude = "Id")] (Related Question) ? Could I write a model binder? 回答1: Yes there is: it's called view models. View models are classes which are specifically tailored to the specific needs of a given view. So instead of: public ActionResult Index([Bind(Exclude = "Id")] SomeDomainModel model) use: public ActionResult Index(SomeViewModel viewModel) where the view model contains only the properties which need to be bound. Then you could map between the view

ASP.NET MVC - Alternative for [Bind(Exclude = “Id”)]

亡梦爱人 提交于 2019-12-28 05:22:08
问题 Is there an alternative for [Bind(Exclude = "Id")] (Related Question) ? Could I write a model binder? 回答1: Yes there is: it's called view models. View models are classes which are specifically tailored to the specific needs of a given view. So instead of: public ActionResult Index([Bind(Exclude = "Id")] SomeDomainModel model) use: public ActionResult Index(SomeViewModel viewModel) where the view model contains only the properties which need to be bound. Then you could map between the view

Why Two Classes, View Model and Domain Model?

≡放荡痞女 提交于 2019-12-27 20:08:59
问题 I know it could be bad to use domain models as view models. If my domain model has a property named IsAdmin and I have a Create controller action to create users, someone could alter my form and get it to POST a IsAdmin=true form value, even if I did not expose such a text field in my view. If I'm using model binding then when I committed my domain model, that person would now be an admin. So the solution becomes exposing just the properties I need in the view model and using a tool like

Why Two Classes, View Model and Domain Model?

為{幸葍}努か 提交于 2019-12-27 20:06:25
问题 I know it could be bad to use domain models as view models. If my domain model has a property named IsAdmin and I have a Create controller action to create users, someone could alter my form and get it to POST a IsAdmin=true form value, even if I did not expose such a text field in my view. If I'm using model binding then when I committed my domain model, that person would now be an admin. So the solution becomes exposing just the properties I need in the view model and using a tool like

ASP.Net MVC 2 - better ModelBinding for Dictionary<int, int>

落爺英雄遲暮 提交于 2019-12-24 12:13:59
问题 In some special cases you will need a list of textboxes (to deal with n - n associations) whose id is not know before runtime. Something like this : http://screencast.com/t/YjIxNjUyNmU In that particular sample I'm looking to associate a count to some of my 'templates'. in ASP.Net MVC 1 I coded a Dictionary ModelBinder to have a clean and intuitive HTML. It allowed things like this : // loop on the templates foreach(ITemplate template in templates) { // get the value as text int val; content

ASP.NET MVC Model Binder not working with a dictionary

穿精又带淫゛_ 提交于 2019-12-24 07:54:47
问题 Given the following view model and action using the DefaultModelBinder , it seems to ignore the dictionary, but bind all other properties correctly. Am I missing something here? Looking at the MVC source code this seems legit. Thanks public class SomeViewModel { public SomeViewModel() { SomeDictionary = new Dictionary<string, object>(); } public string SomeString { get; set; } public IDictionary<string, object> SomeDictionary { get; set; } } [HttpPost] public ActionResult MyAction

MS MVC3 Model Binding an Object

被刻印的时光 ゝ 提交于 2019-12-24 01:48:22
问题 Can someone help me better understand the DefaultModelBinder and how it handles binding a Model that has a property of type object? I've downloaded the code and tried tracing through it, but am still scratching my head a little. Let's say I have a Model like this: public class MyModel{ public object MyProperty{ get; set; } } And assume that my forms are all generated correctly (ex: name="MyModel.MyProperty") What happens for various cases of MyProperty actually being set to instances of