简体   繁体   English

如何从一个cshtml文件调用或使用cshtml文件的功能?

[英]How to call or use function of cshtml file from one cshtml file?

I want to call function of one cshtml file from another cshtml file with parameters. 我想从另一个带有参数的cshtml文件中调用一个cshtml文件的功能。 Both files are cshtml files. 这两个文件都是cshtml文件。 And while pressing button from one page it should redirect on another web page and also execute functionality there. 在按下一个页面上的按钮时,它应该重定向到另一个网页上,并在那里执行功能。 I know one way that I should include in js file and use that js file in both pages. 我知道一种应该包含在js文件中并在两个页面中都使用该js文件的方式。 But I am looking for any other way using jQuery or Ajax call. 但是我正在寻找使用jQuery或Ajax调用的任何其他方式。

window.location.href = redirecturl;

I want redirection on another web page and execute function of that page. 我想重定向到另一个网页并执行该页面的功能。

您的Recretrection URL必须包含类似这样的参数

window.location.href = '/User?name=test&surname=foo';

You want to use a C# Method of a page by another one. 您想使用另一页的C#方法。

To do it, you just have to make an ajax request, targeting as url the other page, followed by the method. 为此,您只需要发出一个ajax请求,将另一个页面作为url作为目标,然后是方法。

I used localStorage.setItem and localStorage.getItem for saving one comman variable value which I need in both cshtml file. 我使用localStorage.setItem和localStorage.getItem保存了两个cshtml文件中都需要的一个逗号变量值。 Added redirection link in one cshtml file of another cshtml file and on load of that second cshtml file used store value of localStorage.getItem in one varibale and cleared value of localStorage.getItem .So,further it can not be used anywhere else. 在另一个cshtml文件的一个cshtml文件中添加了重定向链接,并且在第二个cshtml文件的加载中,使用了一个存储变量中的localStorage.getItem存储值和清除了localStorage.getItem的值。因此,它不能在其他任何地方使用。 And call the need function in load event with conditions. 并在有条件的负载事件中调用Need函数。 This is the easiest way...!!! 这是最简单的方法... !!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 什么是.cshtml文件中的'this'关键字以及如何在a.js文件中使用.cshtml代码 - What is 'this' keyword in .cshtml file and how to use .cshtml code in a .js file 在cshtml文件中加载函数 - Load a function in a cshtml file 如何从javascript / jquery调用cshtml文件? - How should I call a cshtml file from javascript/jquery? 如何从View(cshtml文件)调用JS函数以转到Bootstrap轮播控件中的特定幻灯片? - How to call a JS Function from View(cshtml file) for going to a specific slide in Bootstrap carousel Control? 如何将值从cshtml文件传递给JS - How to pass value from cshtml file to the JS 如何在 cshtml 文件中调用外部 javascript 文件 - How do i call external javascript file in cshtml file 如何将 javascript function(写在 .cshtml 文件中)覆盖到单独的 .js 文件中 - How to override a javascript function (written in a .cshtml file ) into a separate .js file 如何使用 CS 文件中的数据在 CSHTML 文件中创建按钮? - How to create a button in a CSHTML file by using data from a CS file? 如何在cshtml文件中的jquery中调用控制器方法? - How can i call a controller method from jquery in my cshtml file? 有没有办法将.cshtml文件用作chrome扩展名中的弹出窗口? - Is there a way to use a .cshtml file as the popup in a chrome extension?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM