I have got a question very similar to this one how to call javascript function from Controllers file in MVC? but the answer provided wasn't quite what I required.
What I want to do is this, I want to return a view but that I'd like to trigger/call a Javascript/jQuery event. For instance in my controller:
public ActionResult List()
{
// do some processing
// Call the javascript/jquery event
return this.View();
}
Now the way I tried to this was to use the view bag like:
public ActionResult List()
{
ViewBag.MovePanel = "yes";
return this.View();
}
Then in my View I've got soemething like:
<input type="hidden" name="move" id="move" value="<%: (string)ViewBag.MovePanel %>" />
<script type="text/javascript">
$('#move').change(function () {
console.log('changed');
});
The value gets set to "yes" but the "change" event never gets triggered.
How can I achieve what I'm trying to do?
Edit: Following Darin's comment, here is what I am trying to achieve. We are trying to create a form carousel similar to an image carousel. So, what I want to do is control whether the next form is displayed.
For instance, a typical workflow would be something like this:
- Say I am on the first form which is a list of items. I select and item and click edit.
- What then happens is that the list form is hidden from view (but not closed) and the edit form is shown to the user.
- The user then makes some changes to the form and tries to save.
- If there are no validation errors, the edit form is closed and the previous list form is shown into view.
So effectively what I'm having problems with the last step i.e. getting the list form to come into view.
In the wider context say that when I submitted the form and there was an error, then I should be able to keep the "Edit" form in view, not close it and not show the previously opened "List" form.
I hope that this was a clearer explanation.