简体   繁体   中英

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. Both files are cshtml files. 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. But I am looking for any other way using jQuery or Ajax call.

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.

To do it, you just have to make an ajax request, targeting as url the other page, followed by the method.

I used localStorage.setItem and localStorage.getItem for saving one comman variable value which I need in both cshtml file. 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. And call the need function in load event with conditions. This is the easiest way...!!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM