简体   繁体   English

使用javascript调用元素内部的部分视图

[英]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.

相关问题 使用 Javascript 变量作为参数调用局部视图 - Using Javascript variable as a parameter to call a partial view 部分视图中的JavaScript元素格式,但不起作用 - JavaScript element formatting in Partial view, but not functioning angularjs内部内部javascript局部视图不起作用? - Internal javascript inside angularjs partial view is not working? 在AngularJS中部分内部元素的ng-click调用指令 - Call directive from ng-click of element inside a partial in AngularJS 来自javascript的调用控制器方法,可返回常规视图(非局部视图) - Call controller method from javascript that return regular view(not partial) 从ASP.NET MVC Partial View中调用JavaScript - Call JavaScript from within an ASP.NET MVC Partial View 在局部视图中从razor代码调用javascript函数 - call javascript function from razor code in partial view 如何进行ajax调用以获取包含javascript的部分视图? - how to make ajax call to get partial view contains javascript? 如何在纯 JavaScript 中调用已部署的组件(如局部视图) - How to call a react deployed component in plain JavaScript (like a Partial View) 加载部分视图时,Javascript将不会在部分视图内运行 - Javascript won't run inside partial view when partial view is loaded
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM