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

I want to send the itemId and entityModel variables to an ActionResult CreateNote:

public ActionResult CreateNote( [ModelBinder(typeof(Models.JsonModelBinder))] NoteModel Model, string cmd, long? itemId, string modelEntity) 

with this javascript:

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

However, the sending URL

 localhost:1304/Administration/blue/en-gb/Entity/CreateNote?modelEntity=Phrase&itemId=44 

I want to send

 localhost:1304/Administration/blue/en-gb/Entity/CreateNote?modelEntity=Phrase&itemId=44 

How can I prevent Url.Action to put before the second variable that I want to send?

+57
javascript jquery c # url.action
Jan 03 '12 at 11:22
source share
3 answers

Yesterday I didn’t notice that you had & I thought the SO editor changed this. Try wrapping your Url.Action() in @Html.Raw() to prevent & coding.

Or, alternatively, only Url.Action() controller / action bit and pass two parameters as post-data, and not directly to the URL, jQuery should sort it for you as well.

+84
Jan 03 2018-12-12T00:
source share

I think your problem is related to Model.meta.PostAction - is this a string property?

If so, I would suggest that you add it to the page with:

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

Both of them will automatically encode this string for you.

To fix this, use @Html.Raw() / <%= (both of which do not encode) or create a PostAction a IHtmlString property that knows that it is already encoded:

 string actionUrl = Url.Action("CreateNote", new { cmd = "Save", itemId = itemId, modelEntity = modelEntity}); Model.meta.PostAction = new HtmlString(actionUrl); 
+10
Jan 03 2018-12-12T00:
source share

Try it on your JS

 myUrl = myUrl.replace(/&amp;/g, "&"); 
+1
Mar 17 '17 at 18:52
source share



All Articles