Reputation: 5366
As per the title, can an MVC @helper function be called from javascript/JQuery?
@helper DoStuff(string someValue) {
//do some stuff
}
then later on:
$("#MyDropdown").on("change", function() {
@DoStuff('blah')
});
Upvotes: 1
Views: 1660
Reputation: 9281
No, it can't.
The reason for this is because ASP.NET MVC parses the Razor Syntax and compiles it down to C#; where was the Javascript is executed by the visitor's browser.
If you wish to execute a Razor helper like you demonstrate in your question then you're going to need to perform an AJAX call to a controller action and render the helper's output to HTML.
Upvotes: 3