ASP.NET MVC - ViewModels For Edit


ASP.NET MVC - ViewModels For Edit



Is it generally a good practice to have both view and edit models for an MVC app? Meaning, I wouldn't want validation attributes on a view model since it's basically read-only.


Not display/write specific html if model.entity is null

1:

Possible to disable/make item not visable in select list?
I generally create a new view model for each view. Is MVC .net right for my project type?I find this the reuse in practice of ViewModels is just very low and endeavor to make them super generic doesn't job great and leads to any weird cases. Last login time using the ASP.NET Membership API. Weird ASP.NET MVC links with (A(anythingworkshere)) When I first started creating ViewModels I'd create these really abstract ViewModels this I'd try to enforce a bunch of business logic into although then I realized this in most cases the data I was endeavor to show in each case was totally different and reuse wasn't working. What are some alternatives to RedirectToAction?So I just started breaking my ViewModels into really tiny pieces this are used once. What open source software uses ASP.NET MVC [closed]So far this has worked well.. ASP.NET MVC Ajax Actions results enveloping Most of my business logic I now try to keep in the model instead of the view model. I my case my model is a entity framejob model and I put the business logic in partial classes hanging off of my DB objects. .

2:

If your views are CRUD views, using the same view model makes sense. On the read only view, validation attrialthough es would be ignored since you're not inputting a form. Once you receive away from CRUD you have a lot more variations in how to structure your VMs. I have any situations where a field must only be set during insert. In this case I use the same VM for rendering the add, readonly and update screens (with DisplayFor vs InputFor in the view html itself), although I have different input models on my Insert and Update action methods..

3:

You must have a property called ReadOnly (boolean) in your ViewModel. Based on this property appropriate view must be rendered..

4:

You must use your model for editing purposes. You bind editable attrialthough es to the View and another remain same even any body was to fake inputs..
public ActionResult Update([Bind(Include=”First, Last”)]User user) 
This makes sure you just receive the First and Last named fields.. Maybe you missed it although don't display editable inputs for non-editable model attrialthough es..

5:

I think you are misunderstanding the purpose of separating the View and the Model in the Model View Control Pattern.. The View is around defining how the user will see the data i.e. what the web page will look like.. The Model defines this data this will be used i.e. the content this the view will display.. If you decide this you need two different web pages for viewing data and editing data then it would fit the MVC pattern this these two pages should have separate models and views.. But I'm generally against separating viewing and editing data into two web pages. With ajax today I would just did it in one web page. .


66 out of 100 based on 51 user ratings 126 reviews

#