I have a question on how to put my Url Action to razor view:
@Html.EditorFor(m => m.MyTypes, false, new {id = "myId", onchange = "onMyTypeChange('Url.Action("GetMyFields", "MyController")')"})
Do you have any idea how to fix it ?
There seems to be a couple of problems in your syntax for this line of code.
@Html.EditorFor(m => m.MyTypes, false, new {id = "myId", onchange = "onMyTypeChange('Url.Action("GetMyFields", "MyController")')"})
Your second parameter false is useless, since that technically should be of type string since it is for a templateName based on this.
Also as Chris Pratt and I were discussing, in MVC 5.1+ you have to pass your HTML attributes with new { htmlAttributes = new {...} }.
This should help in solving your issue.
@Html.EditorFor(m => m.MyTypes, new { htmlAttributes = new { id = "myId", onchange = "onMyTypeChange('" + Url.Action("GetMyFields", "MyController") + "')" } })
@ haha completely forgot about the keyword discussion.. off to dunkin donuts I go
'? you have an ending'after"MyController")'but where is the leading one?'@Url.Action@, such as@class, becauseclassis a keyword and will be misinterpreted otherwise.idis not a keyword, and is fine.onchangeneeds to be prefixed with@, right?