【问题标题】:Add links to a webgrid ASP.NET MVC3添加指向 webgrid ASP.NET MVC3 的链接
【发布时间】:2013-08-02 15:57:09
【问题描述】:

我正在尝试将链接添加到我的 webgrid 中的各个行。代码如下:

@gridModel1.GetHtml(columns: new[] {
  gridModel1.Column("id"),
  gridModel1.Column("Column2"),
  gridModel1.Column("Column3")
})

表格显示如下:

    id   |  Column2  |  Column3
-------------------------------
    1    |   Stuff   |   Stuff   
-------------------------------
    2    |   Stuff   |   Stuff   
-------------------------------
    3    |   Stuff   |   Stuff   

我还有另一张桌子,就在这张桌子的右边。右边的这个表格应该包含根据用户在我上面显示的表格中选择的内容填充的信息。

我希望在每一行中都有一个链接,以便在单击它时将 id 发送回我的控制器,以便我的控制器可以根据该 id 在我的视图中填充另一个表。

---编辑---

我想出了如何让链接正常工作,但现在我在弄清楚如何在我的控制器中操作它以显示仅与我的 id 相关的信息时遇到了问题。

这是我的控制器:

public ActionResult Index()
{

    // Model1 is the model the table that will be displayed and holds the  
    // id needed to manipulate Model2 
    Model1Repository Model1 = new Model1Repository();
    var Model1RepositorySQL = repoClient.All();

    // Model2 is the table that i need to display the information only 
    // selected from the row selected in Model1 and with the code i have  
    // now it just displays all information
    Model2Repository Model2 = new Model2Repository();
    var Model2RepositorySQL = Model2Repository.All();

    return View(new ParentModelView { Model1 = Model1RepositorySQL, Model2 = 
    Model2RepositorySQL });
 }

有没有人知道我如何能够显示与第一个模型只有相同 id 的信息?

任何帮助将不胜感激,因为我是使用 webgrid 和 MVC 的新手。谢谢!

【问题讨论】:

    标签: asp.net-mvc-3 webgrid


    【解决方案1】:

    这里尽可能接近您在网格内的链接,无需更多关于其余代码的详细信息。希望对你有帮助。

    @gridModel1.GetHtml(columns: new[] {
      gridModel1.Column("id"),
      grid.Column(header: "Column2", format: item => new HtmlString(
               Html.ActionLink((string)item.Column2.ToString(), "Column2ControllerAction", new { id = item.Id } ).ToString())),
      grid.Column(header: "Column3", format: item => new HtmlString(
               Html.ActionLink((string)item.Column3.ToString(), "Column3ControllerAction", new { id = item.Id } ).ToString()))
    })
    

    【讨论】:

    • 感谢您的回复!我决定走一条不同于你上面描述的路线。我使用了从这里找到的以下方法:dotnetcurry.com/ShowArticle.aspx?ID=655I 我仍然相信它会返回行中信息的 URL。我想知道您是否有任何想法来解决我的上述编辑问题?再次感谢!
    猜你喜欢
    • 2013-01-08
    • 2012-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-14
    • 2011-12-07
    • 2013-02-13
    • 1970-01-01
    相关资源
    最近更新 更多