I have a form in view called Role which contains form for filling values for Role. For this i have use model in view.My code is
@using MyProject.Models
@model Role
<h2>AddRole</h2>
@using (Html.BeginForm()){
@Html.LabelFor(m=>m.RoleName)
@Html.TextBoxFor(m=>m.RoleName)<br />
<input type="submit" value="Add Role" />
}
After submitting,it goes to AddRole action in my controller,where I am adding this role to database and return back to same view. code for AddRole is,
[HttpPost]
public ActionResult AddRole(Role role)
{
//Code for adding role into database
using (UserDbContext db = new UserDbContext())
ViewBag.Message= "Role successfully added.";
return View("AddRole");
}
After adding values to database,it is still showing the already type values in textboxes. I want it must not show those values after adding into database.
I think it is,sending that role values back to view,that's why it is showing those values in form.So i try to make that value null in action.But not work. Thanks in advance.