您可以将名称参数添加到操作中。如果我正确理解您在代码中所做的事情......
[HttpGet]
public ActionResult UpdateLead(String name = "")
{
if (!String.IsNullOrEmpty(name))
{
LoginUser user = name as LoginUser;
BusinessLead bl = new BusinessLead();
bl.Name = "some stuff";
return View(bl1);
}
if (user != null)
{
LoginUser user = Session["User"] as LoginUser;
BusinessLead bl = new BusinessLead();
bl.Name = "some stuff";
return View(bl1);
}
return RedirectToAction("Login", "Main");
}
按 ID 执行此操作:
[HttpGet]
public ActionResult UpdateLead(Int32 UserId = -1)
{
LoginUser user = Session["User"] as LoginUser;
if (UserId > -1)
{
BusinessLead bl = new BusinessLead();
bl.Name = "some stuff";
bl = GetUserInfoById(UserId); // Some method you need to make to populate your BusinessLead class based on the id field
return View(bl1);
}
if (user != null)
{
BusinessLead bl = new BusinessLead();
bl.Name = "some stuff";
return View(bl1);
}
return RedirectToAction("Login", "Main");
}
然后你可以在你的 gridview 中使用Html.ActionLink
@Html.ActionLink(UserName, "UpdateLead" "ControllerName", new {name=UserName}, null)
关于您的评论: Html.ActionLink 为您生成链接。如果您想手动合并它,您可以尝试这样的事情:
column.For(x => x.Name).Template("<a href='UpdateLead?name=${Name]'style='color:blue;'>${Name}</a>").HeaderText("Name").Width("10%");
编辑我刚刚注意到你提到了(user ID 3)
. 你可以通过传递一个整数来做同样的事情。您可以让它为空并检查该值,或者将其默认为 0 或其他无法检查的数字。