[英]Add URL.Action to javascript method in Razor View
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 . 您的第二个参数
false
是无用的,因为从技术上讲,该参数应为string
类型,因为它用于基于this的templateName
。
Also as Chris Pratt and I were discussing, in MVC 5.1+ you have to pass your HTML attributes with new { htmlAttributes = new {...} }
. 同样,正如Chris Pratt和我所讨论的那样,在MVC 5.1+中,您必须使用
new { htmlAttributes = new {...} }
传递HTML属性。
This should help in solving your issue. 这应该有助于解决您的问题。
@Html.EditorFor(m => m.MyTypes, new { htmlAttributes = new { id = "myId", onchange = "onMyTypeChange('" + Url.Action("GetMyFields", "MyController") + "')" } })
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.