Url.Action puts an & in my url, how can I solve this?

主宰稳场 提交于 2019-11-29 00:48:06

I didn't notice yesterday that you had & I thought that was the SO editor had changed that. Try wrapping your Url.Action() in a @Html.Raw() to prevent the Encode of &.

Or alternatively only Url.Action() the controller/action bit and pass the two parameters as post data rather than directly on the url, jQuery should sort out the &'s for you that way.

I think your problem is with Model.meta.PostAction - is that property a string?

If so then my guess would be that you're adding it to the page with either:

  • Razor: @Model.meta.PostAction
  • ASP view engine: <%:Model.meta.PostAction%>

Both of which automatically encode that string for you.

To fix it either use @Html.Raw()/<%= (both of which don't encode) or make the PostAction property an IHtmlString that knows that it's already been encoded:

string actionUrl = Url.Action("CreateNote", new { cmd = "Save", itemId = itemId, modelEntity = modelEntity});
Model.meta.PostAction = new HtmlString(actionUrl);

Try this on your JS

myUrl = myUrl.replace(/&amp;/g, "&");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!