Obtain View name in Controller, ASP.NET MVC

前端 未结 4 922
悲&欢浪女
悲&欢浪女 2021-01-25 05:07

I am using asp.net mvc. I have 4 pages that show list of events(different type of events) and \"Details\" link on each page leads to \"EventDescription.aspx\" View.

The

4条回答
  •  醉酒成梦
    2021-01-25 05:33

    When you render the page, you also need to render a link that will point to the correct page when Back to Events is clicked. This is best set up in the controller method, where you readily have access to all of the necessary information.

    An easy way to do this is to put the return link information in a ViewData variable
    (untested pseudocode follows). In your controller method:

    ViewData["ReturnPath"] = "/Content/Page/1";
    

    And then in your view:

    <% =Html.ActionLink("Back To Events", ViewData["ReturnPath"]) %>
    

    or something similar.


    Alternatively, you could try something like

    ViewContext.RouteData.Values["action"]
    

    ...if you don't mind the magic string there. This will give you the calling action.

提交回复
热议问题