I have a view that has a form and a submit button in that form.
When I click the button, the form is posted to the controller/method in the form's action, and the view is redirected to the view in that controller method. All that is good.
Now I need to add links to the view and onclicking one of the links post the form.
I use jquery to submit the form (I have also fired the button click with jQuery)
I do this and the form is posted to the correct controller/method but the view is NOT redirected.
The only difference I see between the two approaches is that the button click is a user action and the call to form submit is a jquery action.
The button that posts back a value from a textbox and a value from 2 radio buttons(name="SearchOption")
one of the Links which is clicked, that posts a hidden input(that holds the value of the clicked link) and a value from 2 radio buttons(name="SearchOption")
I know that "Submit button is the best way to handle the form post" and that is what I am trying to do!!
The button is a submit button, so when the user(me) clicks it, it posts and redirects to the correct view.
But when the user(me again) clicks one of the licks, it posts ok but does not redirect away from that view.
the event that handles the Link onClick:
sets the value of the hidden input
submits the form ie $('#formId')[0].submit();
or fire button click event ie $('#buttonId')[0].click();
The button click posts and redirects the to the desired view.
The submit() from javascript posts, but does not redirect the view
As you can see the jquery library is coming from Telerik so that may be an issue, but it is functioning well for all our other jquery operations(too many to list here)
GregJF
Member
2 Points
10 Posts
Calling form submit from javascript does not redirect to action page
Jul 02, 2012 09:59 PM|LINK
Folks
I have a view that has a form and a submit button in that form.
When I click the button, the form is posted to the controller/method in the form's action, and the view is redirected to the view in that controller method. All that is good.
Now I need to add links to the view and onclicking one of the links post the form.
I use jquery to submit the form (I have also fired the button click with jQuery)
I do this and the form is posted to the correct controller/method but the view is NOT redirected.
The only difference I see between the two approaches is that the button click is a user action and the call to form submit is a jquery action.
Does anybody know what might be going on here
Regards
GregJF
Ken Tucker
All-Star
16797 Points
2608 Posts
MVP
Re: Calling form submit from javascript does not redirect to action page
Jul 02, 2012 11:30 PM|LINK
Did you set the FormMethod to Post when you created the form you submit with javascript?
<% Html.BeginForm("MyAction", "MyController", FormMethod.Post); %>
Space Coast .Net User Group
CPrakash82
All-Star
18720 Points
2899 Posts
Re: Calling form submit from javascript does not redirect to action page
Jul 03, 2012 12:02 AM|LINK
Not sure, how your javascript looks like but why can't you restyle the submit button to look like a link by using style like below.
Please look at the below article to style the button.
http://www.oscaralexander.com/tutorials/how-to-make-sexy-buttons-with-css.html
Submit button is the best way to handle the form post, by this way you need not to worry about enter key to submit the form.
Thanks,
GregJF
Member
2 Points
10 Posts
Re: Calling form submit from javascript does not redirect to action page
Jul 03, 2012 12:45 AM|LINK
Ken
as I said "the form is posted to the correct controller/method", so yes it is Posting and the method does have [HttpPost] attribute
Clicking the button posts.
I know this is posting because there is also a text box and a hidden field(that gets the value of the clicked link) that appear on:
The Posting is not my issue, it is the redirection to the new view.
regards
GregJF
CPrakash82
All-Star
18720 Points
2899 Posts
Re: Calling form submit from javascript does not redirect to action page
Jul 03, 2012 01:05 AM|LINK
Can you post the jquery here ? to suggest some alternative. Also you might was to look at below discussion.
http://stackoverflow.com/questions/199099/how-to-manage-a-redirect-request-after-a-jquery-ajax-call
Thanks,
GregJF
Member
2 Points
10 Posts
Re: Calling form submit from javascript does not redirect to action page
Jul 03, 2012 01:49 AM|LINK
CPrakash82
Yes I could do that
But let me clarify.
I need 2 sets of controls that post the form:
I know that "Submit button is the best way to handle the form post" and that is what I am trying to do!!
The button is a submit button, so when the user(me) clicks it, it posts and redirects to the correct view.
But when the user(me again) clicks one of the licks, it posts ok but does not redirect away from that view.
the event that handles the Link onClick:
The button click posts and redirects the to the desired view.
The submit() from javascript posts, but does not redirect the view
Any clues on why??
regards
GregJF
GregJF
Member
2 Points
10 Posts
Re: Calling form submit from javascript does not redirect to action page
Jul 03, 2012 01:55 AM|LINK
CPrakash82
Please see my other third post
BTW
I am not using ajax on this view, nor do I wish to. Ajax is for getting data back to the SAME view. I want to go to ANOTHER view!!
Regards
GregJF
Young Yang -...
All-Star
21741 Points
1825 Posts
Microsoft
Re: Calling form submit from javascript does not redirect to action page
Jul 09, 2012 01:40 PM|LINK
Hi
Did you include the jquery-x.x.x.js file in your View? If not, please add it.
Hope this helpful
Regards
Feedback to us
Develop and promote your apps in Windows Store
GregJF
Member
2 Points
10 Posts
Re: Calling form submit from javascript does not redirect to action page
Jul 09, 2012 11:17 PM|LINK
Young
As I have pointed out the submit is working and as you can se it is a jquery call so yep I have a reference to a jquery library
Here are my js "links"
<script type="text/javascript" src="/Scripts/2012.2.607/jquery-1.7.1.min.js"></script> <script type="text/javascript" src="/Scripts/2012.2.607/telerik.all.min.js"></script> <script src="/Scripts/jquery.validate.min.js" type="text/javascript"></script> <script src="/Scripts/jquery.validate.unobtrusive.min.js" type="text/javascript"></script> <script src="/Scripts/modernizr.foundation.js" type="text/javascript"></script> <script src="/Scripts/foundation.js" type="text/javascript"></script> <script src="/Scripts/app.js" type="text/javascript"></script> <script src="/Scripts/json/json2.js" type="text/javascript"></script> <script src="/Scripts/inline/_layout_inline.js" type="text/javascript"></script>As you can see the jquery library is coming from Telerik so that may be an issue, but it is functioning well for all our other jquery operations(too many to list here)
Regards
GregJF
vogelra
Member
44 Points
20 Posts
Re: Calling form submit from javascript does not redirect to action page
Jul 10, 2012 03:23 AM|LINK