嗨,我有一個註冊頁面,它包含稱爲UID,用戶名,密碼的字段。我正在使用dev Express gridview。當我點擊編輯按鈕時,它需要將特定的行鍵值傳遞給控制器,但它將空參數傳遞給控制器。現在我想要的是我想通過單擊編輯按鈕在網格視圖中使用SetDataItemTemplateContent.Below mvc dev表格gridview中的編輯按鈕將特定的行鍵參數傳遞給控制器我發佈我的代碼請任何一個更正我的代碼,並告訴我我做了什麼錯誤。如何通過點擊編輯按鈕使用mvc4 devExpress中的SetDataItemTemplateContent將參數從gridview傳遞到控制器?
我的模型(UserMasterViewModel)
public int UID{get;set;}
public string UserName{get;set;}
public string Password{get;set;}
我的控制器代碼
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)
}
網格視圖代碼
@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()
編輯觀點
@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>
在這個我點擊編輯按鈕將它傳遞空值到控制器。我嘗試了很多方法,但無法將UID參數傳遞給控制器。 我不知道我在這個動作中犯了什麼錯誤。我盡我最大努力解釋這個問題任何人都明白並幫助我解決這個問題。
謝謝..