在这种情况下,什么是正确的 MVC 2 页面导航协议

发布于 2024-11-17 22:10:55 字数 1206 浏览 3 评论 0原文

我的任务正在取得进展,但遇到了一个小症结。当我研究它时,我想我应该在这个论坛上提出这个问题,这样如果其他人遇到类似的问题,他们可以依靠我们在这里提供的奖学金。

说到这个问题... 我将从 XML 字符串接收到的数据呈现为网格格式的视图。我希望能够通过单击该行中的链接导航到另一个页面。该链接将带我到所提供数据的另一个更详细的视图。我将使用链接上显示的一些数据来查询 xml(通过 LINQ to XML)并获取要在下一页(视图)上呈现的相应行。我的问题是,我该如何在 MVC 中做到这一点?在普通的 asp.net 中,我只是将该信息放入查询字符串或其他一些简单的状态管理变量中。我有点困惑如何使用 MVC2 完成此任务?
这是我当前拥有的代码

     <% foreach (var item in Model) { %>

    <tr>
        <td>                
            <%: Html.ActionLink("View Detailed Patient Info", "TemplateInfo", "PatientACO", new {  PopulationPatientID=item.PopulationPatientID } )%> |                
        </td>
        <td>
            <%: item.populationID %>
        </td>
        <td>
            <%: item.PopulationPatientID%>
        </td>
        <td>
            <%: item.populationOwner %>
        </td>
        <td>
            Table Column3
        </td>
    </tr>

<% } %>

该代码在我的视图中,我想将该 PopulationPatientID 发送到控制器,然后该控制器将使用它来查询我的 XML。我可以使用 HTML.ActionLink() 的重载来帮助我解决这个问题吗?我是否提到过我尝试导航到的 ActionLink 需要字符串参数?任何帮助或想法都会很棒。我将继续我的研究,如果我遇到行业标准的方法,我将发布答案。

谢谢。

I am making progress in my assignment, but have run into a minor sticking point. While I research it, I thought I would ask the question on this forum so if any one else runs into a similar issue, they can rely on the scholarship we present here.

On to the question...
I am rendering data I receive from an XML string into views in a grid format. I want to be able to navigate to another page by clicking on a link that is in that row. That link will take me to another more detailed view of the data presented. I will use some of the data that is display on the link to query my xml (via LINQ to XML) and get the appropriate rows to render on the next page (view). My question is, how would I do this in MVC? In vanilla asp.net I would just put that information into the querystring or some other simple state-management variable. I am little confused how to get this done using MVC2?
Here is the code of what I currently have

     <% foreach (var item in Model) { %>

    <tr>
        <td>                
            <%: Html.ActionLink("View Detailed Patient Info", "TemplateInfo", "PatientACO", new {  PopulationPatientID=item.PopulationPatientID } )%> |                
        </td>
        <td>
            <%: item.populationID %>
        </td>
        <td>
            <%: item.PopulationPatientID%>
        </td>
        <td>
            <%: item.populationOwner %>
        </td>
        <td>
            Table Column3
        </td>
    </tr>

<% } %>

That code is in my view, and I want to send that PopulationPatientID to a controller that will then use it to query my XML. Is there an Overload to HTML.ActionLink() that I can use that will help me out with that at all? Did I mention that the ActionLink that I am trying to navigate to requires a string parameter? Any help or ideas would be fantastic. I'll continue my research, and should I come across an industry standard way of doing it I will post an answer.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深海夜未眠 2024-11-24 22:10:55

您没有提及您的路由设置,但如果您仍在使用默认值...

    routes.MapRoute(
        "Default", // Route name
        "{controller}/{action}/{id}", // URL with parameters
        new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults

您指定了操作 (TemplateInfo) 和控制器 (PatientACO),但将 id 参数的名称更改为 PopulationPatientID。请记住,参数名称在 MVC 中很重要(约定与配置)。因此,将 ActionLink() 调用更改为:

    <%: Html.ActionLink("View Detailed Patient Info", "TemplateInfo", "PatientACO", new {  id=item.PopulationPatientID } )%> |                

You don't mention your routing setup, but if you are still using the defaults...

    routes.MapRoute(
        "Default", // Route name
        "{controller}/{action}/{id}", // URL with parameters
        new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults

You specified the action (TemplateInfo) and controller (PatientACO), but you changed the name of the id parameter to PopulationPatientID. Remember that the name of the parameter is important in MVC (convention vs. configuration). So change your ActionLink() call to:

    <%: Html.ActionLink("View Detailed Patient Info", "TemplateInfo", "PatientACO", new {  id=item.PopulationPatientID } )%> |                
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文