[英]Call partial view inside element with javascript
I Have a function called ValidarLogueo, which will return 0 for common users and 1 for administrator users. 我有一个称为ValidarLogueo的函数,该函数对于普通用户将返回0,对于管理员用户将返回1。 I'm trying to do somthing like this but it's giving me a bad compile constant value error. 我正在尝试做这样的事情,但这给了我一个不好的编译常量值错误。
<input id="Logueo" value="Login" class="btn btn-info btn-block" onclick="javascript:validarLogueo() == 0? @Url.Action('VistaViandasPersonal', 'Menu'): @Url.Action('VistaAdministrador', 'Menu')">
I'm now rendering the page in my .js like this, but it's not what i need due to the url keeps in localHost, instead of localHost/Menu 我现在以这种方式在.js中呈现页面,但是由于URL保留在localHost中而不是localHost / Menu中,因此这不是我需要的
$('body').load(url + '/Menu/VistaViandasPersonal');
Is there anything I can do to achive that. 我能做些什么来实现这一目标。 Thanks in advance. 提前致谢。
If you expand the generated code manually, you will see you are trying to inject string constants , but have not included the delimiting quotes. 如果您手动扩展生成的代码,将会看到您正在尝试注入字符串常量 ,但没有包括定界引号。 Add single quotes around the @Url.Action
calls. 在@Url.Action
调用周围添加单引号。
eg 例如
<input id="Logueo" value="Login" class="btn btn-info btn-block"
onclick="javascript:validarLogueo() == 0 ? '@Url.Action('VistaViandasPersonal', 'Menu')' : '@Url.Action('VistaAdministrador', 'Menu')'">
I strongly recommend you move to using a jQuery event handler and never use inline handlers with jQuery. 我强烈建议您转而使用jQuery事件处理程序,而不要对jQuery使用内联处理程序。 When you need a root site URL, that can be injected by your master page into a global variable 当您需要根站点URL时,母版页可以将其注入到全局变量中
<script>
window.siteRoot = "@Url.Content("~")";
</script>
and simply prepend this to any URLs in your jQuery code. 并将其简单地添加到jQuery代码中的所有URL之前。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.