1

I have a web site written using ASP.NET MVC3.
The site has one single web page and what I want to do is to have the controller handle the request, do some parsing and processing and thereafter trigger a certain javascript method in the single webpage based on part of the data from the request.

How would I do this in the MVC controller?

1 Answer 1

1

You can't directly trigger actions in the View from the controller.

However, what you can do is return an ActionResult from the Controller Action to the View that instructs the View to execute your Javascript.

This could be a PartialView that includes the Javascript (in which case, you'll need a placeholder in your view for the PartialView to be rendered 'into') or something like a JSONResult that contains a property instructing the logic within the View what to do.

Either way, the call to the Controller Action is going to be triggered by client-side Javascript and your desired logic executed when the Controller Action finishes executing.

You'll probably find it easier to use jQuery.

Sign up to request clarification or add additional context in comments.

1 Comment

Excuse my ignorance... but how would I trigger the javascript from the partial view?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.