0

让我看看我是否可以更清楚地说明我在寻找什么。

我有一个视图“UpdateLead”

在我的控制器中的 GET 上,我有..

[HttpGet]
public ActionResult UpdateLead()
{
    LoginUser user = Session["User"] as LoginUser;
    if (user != null)
    {
         BusinessLead bl = new BusinessLead();
         bl.Name = "some stuff";

         return View(bl1);
    }
    return RedirectToAction("Login", "Main");
}

所以当我看到视图时,“名称”字段有文本“一些东西”..

但我想要的基本上是从另一个名为“ViewLeads”的视图上的网格视图中获取“名称”信息。gridview 是一个 Infragistics 网格。所以基本上如果用户选择网格中的第三个用户,我想返回该用户的所有数据(用户 ID 3)。我对 MVC 很陌生,我现在完全迷路了。谢谢!

4

1 回答 1

0

您可以将名称参数添加到操作中。如果我正确理解您在代码中所做的事情......

[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 或其他无法检查的数字。

于 2014-08-21T18:32:07.217 回答