[英]Asp.Net MVC parameter is null when pass it from client side to controller
Javascript Java脚本
I have a method as follows, 我有以下方法
function OpenRecord(id ,module ,screen) {
var url = '@Url.Action("OpenRecord", "Management", new { id = "_id", module = "_module",screen = "_screen" })';
url = url.replace("_id", encodeURIComponent(id));
url = url.replace("_module", encodeURIComponent(module));
url = url.replace("_screen", encodeURIComponent(screen));
window.location.href = url;
}
Controller 控制者
public ActionResult OpenRecord(string id, string module, string screen)
{
Int64 someID = Convert.ToInt64(id);
/*some act**/
return RedirectToAction(screen, module, new { id = someId});
}
When I run this i get id and module but screen param is passed null . 当我运行它时,我得到了id和模块,但是屏幕参数传递了null 。 When i inspect client side on chrome dev tools, i see all the parameters on javascript method are filled and the final url in url variable as follows;
当我在chrome开发工具上检查客户端时,我看到javascript方法上的所有参数都已填充,并且url变量中的最终url如下;
/Management/OpenRecord/112?module=Customer&screen=MUSTRTANML
I guess that amp&; 我猜那个amp&; entity spoils my controller to get the last param but i am not sure and i don't know how to solve this.
实体破坏了我的控制器以获得最后一个参数,但是我不确定,我也不知道如何解决这个问题。
Thanks in advance. 提前致谢。
Simply wrap your Url.Action
in Html.Raw()
. 只需将您的
Url.Action
包装在Html.Raw()
。 Or you can go with replacement approach further - url = url.replace("&", "&")
. 或者,您可以进一步采用替换方法
url = url.replace("&", "&")
。 Whatever you like, personally I would proceed with Html.Raw
无论您喜欢什么,我个人都会继续使用
Html.Raw
you need to construct your url string with values 您需要使用值构造网址字符串
var url = '@Url.Action("OpenRecord", "Management", new { id = "_id", module = "_module",screen = "_screen" })';
this is wrong, it should be 这是错误的,应该是
var url = '/Management/OpenRecord?id=' + _id + '&module='+ _module + '&screen='+ _screen;
the above will pass the values of the variables rather than names , you cannot execute Url.Action as part of JavaScript this is Razor code 上面的将传递变量的值而不是名称,您不能将Url.Action作为JavaScript的一部分执行,这是Razor代码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.