kala-tamin asp.net mvc2 - how to get model and model.something in the same way in controller?


asp.net mvc2 - how to get model and model.something in the same way in controller?



If my Model is Contacts then I can easily get it in controller like this:

[HttpPost] public ActionResult Create(Contact contact) ... 

But if my Model is wrapper for Contacts and something else then in View I display it using Model.contact.

How to get Contact in Controller the same way like I did in first case? I don't want to use Formcollection.




Using ASP.NET MVC 2, StructureMap, Fluent NHibernate, and PostgreSQL

1:



ASP.NET MVC application security
If you want to bind only the Contact but it is not the Model of your view but it is part of it as you have written, you can do the following for create:.
What separates self taught from trained professional devolpers? [closed]
[HttpPost] public ActionResult Create([Bind(Prefix = "Contact")]Contact contact) 
And for the edit you can do the same, and you need to specify also in UpdateModel the prefix, like this: .
What is causing this DatabaseFileLockedException when trying to open a db4o database in an ASP.NET MVC app?
    [HttpPost]     public ActionResult Edit([Bind(Prefix = "Contact")]Contact contact){       UpdateModel(contact, "Contact");     } 


ASP.NET MVC Experiences/Success Stories [2010]


MVC2 Html Helpers

2:



What is the difference if a Views' “head” tag has attribute “runat” or not?
For example you have.
Asp.net MVC route url
public class MyViewModel {     Contact MyContact { get; set; }     Object SomethingElse { get; set; } } 
You can get it back by using the same type object as parameter:.
[HttpPost] public ActionResult Create(MyViewModel returnedModel) {     Contact returnedContact = returnedModel.MyContact;     // ... 

}


3:


You could use model binders: there are already some answers on stackoverflow about that: ASP.NET MVC2 - Custom Model Binder Examples.



83 out of 100 based on 63 user ratings 713 reviews