Asp.net mvc MVC从GridView获取数据以在视图上显示

Asp.net mvc MVC从GridView获取数据以在视图上显示,asp.net-mvc,gridview,infragistics,ignite-ui,iggrid,Asp.net Mvc,Gridview,Infragistics,Ignite Ui,Iggrid,让我看看我是否能更清楚地说明我在找什么 我有一个“UpdateLead”视图 在进入我的控制器时,我有 [HttpGet] public ActionResult UpdateLead() { LoginUser user = Session["User"] as LoginUser; if (user != null) { BusinessLead bl = new BusinessLead(); bl.Name = "some st

让我看看我是否能更清楚地说明我在找什么

我有一个“UpdateLead”视图

在进入我的控制器时,我有

[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");
}
因此,当我看到视图时,“name”字段包含一些文本内容


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

您可以将name参数添加到操作中。如果我正确理解您在代码中的操作

[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(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%‌​");

编辑我刚刚注意到你提到了用户ID 3。您可以通过传递一个整数来执行相同的操作。您可以使其为空并检查值,或者将其默认为0或其他一些它永远无法检查的数字。

我如何将其合并到我的基础设施网格中?我的网格代码看起来像。。。column.Forx=>x.Name.Template.HeaderTextName.Width10%;嗨,奥马尔,你可能想在你的问题中的代码块内包含该代码!在评论中很难读到。考虑到这一点,您可以将?name=$[name]附加到您的href。对此表示抱歉。谢谢所以我试过了,现在它的名字传过来了。我是否需要对所有其他字段执行相同的操作?或者像上面所说的那样传递ID会给出我需要的网格中的所有值吗?如果你有一种通过ID获取数据的方法,那么是的,ID将是最好的。您也可以根据名称进行查找,但更好的做法是根据id进行查找,因为id是唯一的,而名称并不总是唯一的。如何做到这一点完全取决于数据的存储方式。