我有一个带有actionlink的webgrid,我想用它来编辑新视图中的选定行。我知道我可以使用actionlink为我的actionresult方法提供一个争论但我不知道除了使用actionlink之外如何将webgrid的行数据传递给我的控制器。
@{
ViewBag.Title = "Index";
}
<h2>
Index</h2>
<p>
@Html.ActionLink("Create New User", "CreateUser")
</p>
<div class="webgrid-wrapper">
@model IEnumerable<UserManager.Models.vw_UserManager_Model_Add_Users>
@{
ViewBag.Title = "Jobs";
WebGrid grid = new WebGrid(Model, canPage: true, canSort: true, rowsPerPage: 15, selectionFieldName: "selectedRow", fieldNamePrefix: "gridItem");
}
@grid.GetHtml(
fillEmptyRows: true,
tableStyle: "webgrid",
alternatingRowStyle: "webgrid-alternating-row",
headerStyle: "webgrid-header",
footerStyle: "webgrid-footer",
selectedRowStyle: "webgrid-selected-row",
rowStyle: "webgrid-row-style",
mode: WebGridPagerModes.All,
columns: new[] {
//grid.Column("ApplicationId"),
//grid.Column("salutation"),
//grid.Column("PasswordSalt"),
grid.Column("FirstName"),
//grid.Column("LoweredEmail"),
//grid.Column("PasswordQuestion"),
//grid.Column("PasswordAnswer"),
// grid.Column("PasswordFormat"),
grid.Column("LastName"),
grid.Column("Password"),
grid.Column("isactive"),
//grid.Column("IsLockedOut"),
grid.Column("email"),
grid.Column("module_name"),
//grid.Column("LastLoginDate"),
//grid.Column("LastPasswordChangedDate"),
//grid.Column("LastLockoutDate"),
//grid.Column("FailedPasswordAttemptCount"),
//grid.Column("FailedPasswordAttemptWindowStart"),
//grid.Column("FailedPasswordAnswerAttemptCount"),
//grid.Column("FailedPasswordAnswerAttemptWindowStart"),
// Rest of grid columns, seen previously
@*grid.Column(
"",
header: "Actions",
format: @<text>
@Html.ActionLink("Edit", "Edit", new { id = item.email })
</text>
) ,
grid.Column(
"",
header: "Actions",
format: @<text>
@Html.ActionLink("Delete", "Delete", new { id = item.email })
</text>
) *@
@* grid.Column(
header:"",
format:@<text><div id="btnSelectedRow">
"@item.GetSelectLink("Edit")</div></text>
),*@
grid.Column(
header:"",
format:@<text><div id="btnSelectedRow">
"@Html.ActionLink("Edit record",
"EditUser",
"UserManager",
new {selectedRow = grid.SelectedRow },
null
)</div></text>
)
})
@if (grid.HasSelection)
{
var record = grid.SelectedRow;
@*@RenderPage("~/Views/UserManager/EditUser.cshtml", new { record = grid.SelectedRow })*@
}
</div>
<script type="text/javascript">
$(document).ready(function () {
function jQueryUIStyling() {
$('input:button, input:submit').button();
// Style tables.
$('.webgrid-wrapper').addClass('ui-grid ui-widget ui-widget-content ui-corner-all');
$('.webgrid-title').addClass('ui-grid-header ui-widget-header ui-corner-top');
jQueryTableStyling();
}
//
// Style tables using jQuery UI theme. This function is
// split out separately so that it can be part of the AJAX
// callback of the WebGrid WebHelper in ASP.NET MVC.
//
function jQueryTableStyling() {
$('.webgrid').addClass('ui-grid-content ui-widget-content');
$('.webgrid-header').addClass('ui-state-default');
$('.webgrid-footer').addClass('ui-grid-footer ui-widget-header ui-corner-bottom ui-helper-clearfix');
}
});
</script>
我的控制器
public ActionResult EditUser(System.Web.Helpers.WebGrid record)
{
record.ToString();
return View();
}
摘要
如何使用ActionLink通过ActionResult方法将行数据从一个视图传递到另一个视图。
答案 0 :(得分:2)
您有两个选择,实际上:让您的操作获取用户ID并查看用户,或者让网格的每一行都包含一个表单,该表单会在您单击“编辑”时将所有用户详细信息发送到操作。您选择哪一个取决于您的行动应该做什么:
修改强>
要传递ID,您可以将其用于操作链接:
@Html.ActionLink(
"Edit record",
"EditUser",
"UserManager",
new { id = item.email })
...这是动作签名:
public ActionResult EditUser(string id)