Hi All,
I have a view like
@model MySite.Models.RoleModel
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
WebGrid grid = new WebGrid(@Model.RoleList);
}
<div>
Enter role name:<br />
@Html.TextBox("RoleName", null, new { width = "300px" })
</div>
<div id="container-grid">
@* @grid1.GetHtml()*@
@grid.GetHtml(
columns: new[] {
grid.Column("RoleName"),
grid.Column(header: "Edit", format: @<text><a href="@Url.Action("Edit", "Role", new { id = item.RoleId })" >
<img src="../../images/edit.png" alt="" style="border: none;" /></a></text>),
grid.Column(header: "Delete", format: @<text><a href="@Url.Action("Delete", "Role", new { id = item.RoleId })"
onclick="javascript:return ConfirmDelete();"><img src="../../images/grid_delete.png"
alt="" style="border: none;" /></a>
</text>)
})
</div>
<input type="button" value="Save" id="Save" />
====================================
On Load in index method of Rolecontroller
public ActionResult Index()
{
RoleModel objRoleModel=FillModel(); //Getting existing roles form db and sending to view
return View(objRoleModel);
}
Grid is loading correctly but on Save button click through ajax call i am calling the controller method
$('#Save').click(function () {
debugger;
var url = "/Role/SaveRole";
var name = $("#RoleName").val();
$.ajax({
type: "POST",
url: url,
data: { RoleName: name, SelectedRoles: roleArray },
success: function (data) {
debugger;
},
traditional: true
});
})
and in corresponding controller
public ActionResult SaveRole(String RoleName,List<string> SelectedRoles)
{
Saving role in database.......here.
//and returning the index view from here
RoleModel objRoleModel=FillModel(); //Getting existing roles form db and sending to view
Return View("Index",objRoleModel);
}
however on view while debugging i am seeing the model with last role saved, but in grid it is not reflecting???
If you have any idea please go through it.
thanks