0

I have the following MVC Url Helper:

 var result = $(this).val();

 var url = '@Html.Raw(Url.WpActionUrl((object)@ViewBag.Org_ID, "DocumentList", "MP", (object)result,null, null))';

The problem that I am experiencing is that the code will not recognize"result" in the MVC Url Helper.

I tried to delimit the single quote but no luck.

 var url = '@Html.Raw(Url.WpActionUrl((object)@ViewBag.Org_ID, "DocumentList", "MP", (object) ' + result + ',null, null))';
Nate Pet
  • 44,246
  • 124
  • 269
  • 414
  • You cannot use a value known only in JavaScript, client-side, in code that runs server-side. –  Jan 30 '20 at 19:48
  • @Amy I am trying to just update the url so it an accept it. This is all in the View so not sure why it would not be possible. – Nate Pet Jan 30 '20 at 19:53
  • Your view is rendered server-side, before the client-side code has a chance to run. –  Jan 30 '20 at 19:56
  • Does this answer your question? [How to pass a value to razor variable from javascript variable?](https://stackoverflow.com/questions/28317182/how-to-pass-a-value-to-razor-variable-from-javascript-variable) –  Jan 30 '20 at 19:57
  • 1
    This is a duplicate of your [previous question](https://stackoverflow.com/questions/59973517/pass-object-type-as-parameter-in-javascript). Please refrain from duplicating your questions. You can edit it to provide more information, which will (probably) move it to the top of the home page. –  Jan 30 '20 at 20:03
  • Do this: https://stackoverflow.com/questions/10389649/possible-to-access-mvc-viewbag-object-from-javascript-file – Steve Greene Jan 30 '20 at 20:28
  • @SteveGreene That's going the wrong direction, from Razor->JS. This question is asking how to get a JS value into Razor, which cannot be done. –  Jan 30 '20 at 21:42
  • Sounds like an [XY Problem](https://en.wikipedia.org/wiki/XY_problem). If you need to get data server to client or vice versa there are techniques. Hidden fields come to mind. – Steve Greene Jan 30 '20 at 21:49

0 Answers0