Reputation: 1234
I have this action:
[HttpPost]
public ActionResult Test(Test test)
{
...
}
With this class:
public class Test
{
public string txtTest { get; set; }
}
An html form has a text field named txtTest, and I can successfully call into my action above. What property name would allow me to do this:
public class Test
{
[SomeAttribute(Name = "txtTest")]
public string MyTest { get; set; }
}
Upvotes: 0
Views: 922
Reputation: 150313
Use ViewModel, don't use classes which are being used for something else.
Create ViewModel, for this specific View only.
one of the benefits is you don't need to change the names of properties the existing classes have.
You can use automapper
which is highly used in MVC applications to map from the ViewModel to the Entity.
A good reading resource can be found here
Upvotes: 2
Reputation: 4107
Use the Display DataAnnotation
http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.displayattribute.aspx
Upvotes: 1