Hi i have one registration page and it contain fields called UID,UserName,Password. I am using dev Express gridview. When i click the edit button it need to pass the particular row key value to controller but it passing null parameter to controller. Now what i want is i want to pass the particular row key Parameter to controller by clicking edit button in grid view in mvc dev express gridview using SetDataItemTemplateContent.Below i post my code please any one correct my code and tell me what mistake i did.
My Model (UserMasterViewModel)
public int UID{get;set;}
public string UserName{get;set;}
public string Password{get;set;}
My Controller Code
Public ActionResult UserMasterEdit(int? id)
{
View_MUsrRegistration userregistrartion = db.MUsrRegistration.Find(id)
UserMasterViewModel usermasterviewmodel = new UserMasterViewModel();
usermasterviewmodel.UserName = userregistrartion.UserName;
usermasterviewmodel.Password = userregistrartion.Password;
return View(usermasterviewmodel)
}
Grid View Code
@Html.DevExpress().GridView(
settings =>
{
settings.Name = "gvEditing";
settings.KeyFieldName = "UID";
settings.CallbackRouteValues = new { Controller = "UserMaster", Action = "UserMasterPartial" };
settings.Width = Unit.Percentage(100);
settings.Columns.Add(column => {
column.Caption = "#";
column.SetDataItemTemplateContent(c =>
{
ViewContext.Writer.Write(
Html.ActionLink("Edit", "UserMasterEdit", new { UID = DataBinder.Eval(c.DataItem, "UID") }) + " " +
Html.ActionLink("Delete", "UserMasterDelete", new { ProductID = DataBinder.Eval(c.DataItem, "UID") },
new { onclick = "return confirm('Do you really want to delete this record?')" })
);
});
column.Settings.AllowDragDrop = DefaultBoolean.False;
column.Settings.AllowSort = DefaultBoolean.False;
column.Width = 70;
});
settings.Columns.Add("UserName");
settings.Columns.Add("Password");
settings.ClientLayout = (s, e) =>
{
if(e.LayoutMode == ClientLayoutMode.Loading) {
if(Session["GridState"] != null)
e.LayoutData = (string)Session["GridState"];
}
else
Session["GridState"] = e.LayoutData;
};
}).Bind(Model).GetHtml()
EDIT View
@model MSSERP.Models.UserMasterViewModel
@{
Html.EnableClientValidation();
}
@using(Html.BeginForm("UserMaterUpdate", "UserMaster", FormMethod.Post, new { @class = "edit_form" })) {
@Html.HiddenFor(m=>m.UID)
<div class="line">
@Html.Label(UserNmae)
@Html.TextBoxFor(m=>m.UserName)
</div>
<div class="line">
@Html.Label(Password)
@Html.TextBoxFor(m=>m.Password)
</div>
<div class ="line">
<input type="submit" value ="Save"/>
</div>
In this i am clicking edit button it passing the null value to controller. I tried many ways but cant able to pass the UID parameter to controller. i donno what mistake i did in this action. I tried my level best to explain this issue Any one understand and help me to resolve this issue.
Thanks..