I was going through a action method code and i saw one attribute was used there but i really did not understand the use. here is the code
public ActionResult User([Bind(Include = "Username,FullName,Email")]User user)
{
if (!ModelState.IsValid()) return View(user);
try
{
user.save()
// return the view again or redirect the user to another page
}
catch(Exception e)
{
ViewData["Message"] = e.Message;
return View(user)
}
}
([Bind(Include = "Username,FullName,Email")]User user)
i just do not understand the above line Bind include etc
so please help me to understand this kind of attribute used & when people write this kind of code in mvc. it will be really good help if some one make me understand with sample small code where they will use this Bind attribute
.
Update: Suppose i have form from where user can enter only FirstName,LastName & Gender then my action method looks like
public ActionResult Edit(string FirstName,string LastName,string Gender)
{
// ...
}
this will work i think. then why i should use a Bind Attribute because my above action method will works fine.