开发者

ASP.NET MVC The new ActionLink with MvcHtmlString and request URL generated

开发者 https://www.devze.com 2022-12-23 05:41 出处:网络
This piece of code used to work in MVC 1 but it does not since I upgraded to MVC 2: <%=Html.ActionLink(Resources.Localize.Routes_WidgetsCreate, \"Create\" + \"?modal=true\", \"Widget\", null,

This piece of code used to work in MVC 1 but it does not since I upgraded to MVC 2:

    <%=Html.ActionLink(Resources.Localize.Routes_WidgetsCreate, "Create" + "?modal=true", "Widget", null,
                                      new
                                        {
                                            rel = "shadowbox;height=600;width=700",
                                            title = Resources.Localize.Routes_WidgetsCreate
                                        })%>

I am aware it has something to do with the way that new ActionLink helper encodes things, so the result that comes out is something like this:

"http://localhost:53704/Widget/Create%3fmodal%3dtrue"

The problem is, when clicked, the Shadowbox modal opens up and inside, where the request View should be rendered is this exception:

Server Error in '/' Application.

A potentially dangerous Request.Path value was detected from the client (?).

What can I do to get past that? Do you recommend another way of sending params to the view besides in QueryString (in this case I need "modal" because i开发者_C百科n the view I select CSS styles based on whether we are rendering modal or not)?


You should not build query string parameters this way in MVC one, either. Instead, add them as Route value tokens:

<%=Html.ActionLink(Resources.Localize.Routes_WidgetsCreate, "Create",                       "Widget", 
                                  new
                                  {
                                      modal = true
                                  },
                                  new
                                    {
                                        rel = "shadowbox;height=600;width=700",
                                        title = Resources.Localize.Routes_WidgetsCreate
                                    })%>

Anything which does not match an identifier in the route itself will be appended as a query string parameter.

0

精彩评论

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