开发者

What is Proper MVC 2 Page Navigation Protocol in this instance

开发者 https://www.devze.com 2023-03-16 10:09 出处:网络
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

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 si开发者_C百科mple 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.


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 } )%> |                
0

精彩评论

暂无评论...
验证码 换一张
取 消