Re: Basic MVC4 question on Form Post
I'd also suggest to go straight to T4MVC for some strongly typed goodness :) http://t4mvc.codeplex.com/ Neil. On 4 November 2013 15:58, GregAtGregLowDotCom g...@greglow.com wrote: Thanks guys. I was suspecting that’s roughly what’s needed. I had just found that I could name a form, similarly to what you had mentioned so that was a good start. I’ll try the script. Regards, Greg Dr Greg Low 1300SQLSQL (1300 775 775) office | +61 419201410 mobile│ +61 3 8676 4913fax SQL Down Under | Web: www.sqldownunder.com *From:* ozdotnet-boun...@ozdotnet.com [mailto: ozdotnet-boun...@ozdotnet.com] *On Behalf Of *Tony Wright *Sent:* Monday, 4 November 2013 4:51 PM *To:* 'ozDotNet' *Subject:* RE: Basic MVC4 question on Form Post Add an id to your BeginForm statement, in case you have a second form to the page (there’s usually a separate form tag for logout button, if I recall correctly.) using (Html.BeginForm(foo, bar, FormMethod.Post, new { id = myID })) You need to add a click handler to the span containing the text and then perform a form submit there, referencing the id tag. You can add the click handler in the document.ready. $(document).ready(function () { $('body').on('click', '#mySpanId', function () { $(form#myID).submit(); }); This is off the top of my head and is only one possible solution. You might need to check the syntax. *From:* ozdotnet-boun...@ozdotnet.com [ mailto:ozdotnet-boun...@ozdotnet.com ozdotnet-boun...@ozdotnet.com] *On Behalf Of *GregAtGregLowDotCom *Sent:* Monday, 4 November 2013 4:33 PM *To:* ozDotNet *Subject:* Basic MVC4 question on Form Post Hi Folks, I’m still getting my head around MVC4 bit by bit. A quick question if I can: If I have a form declared: @using (Html.BeginForm(SomeAction, SomeController”, FormMethod.Post)) { } I would normally just post it by using an input button set to submit. However, if I don’t want to use a button but want to make the form post when someone clicks on some text in a div contained in the form, how do you do that? Do you have to make an onclick for the div execute some java to post the form? If so, how would you select the form using jQuery in this case? (If I code forms myself, I can give them a name but this Html helper doesn’t seem to have a name). Thanks! (I’ll be back to databases where I know what I’m doing soon J) Regards, Greg Dr Greg Low CEO and Principal Mentor *SQL Down Under* SQL Server MVP and Microsoft Regional Director 1300SQLSQL (1300 775 775) office | +61 419201410 mobile│ +61 3 8676 4913fax Web: www.sqldownunder.com
Basic MVC4 question on Form Post
Hi Folks, I'm still getting my head around MVC4 bit by bit. A quick question if I can: If I have a form declared: @using (Html.BeginForm(SomeAction, SomeController, FormMethod.Post)) { } I would normally just post it by using an input button set to submit. However, if I don't want to use a button but want to make the form post when someone clicks on some text in a div contained in the form, how do you do that? Do you have to make an onclick for the div execute some java to post the form? If so, how would you select the form using jQuery in this case? (If I code forms myself, I can give them a name but this Html helper doesn't seem to have a name). Thanks! (I'll be back to databases where I know what I'm doing soon :)) Regards, Greg Dr Greg Low CEO and Principal Mentor SQL Down Under SQL Server MVP and Microsoft Regional Director 1300SQLSQL (1300 775 775) office | +61 419201410 mobile│ +61 3 8676 4913 fax Web: http://www.sqldownunder.com/ www.sqldownunder.com
Re: Basic MVC4 question on Form Post
I’m guessing, something like will get you close. $('div').click( $('form[action=SomeAction]').submit() ) I hope the action is unique enough I don’t know how mvc renders them now.. From: Greg Low g...@greglow.commailto:g...@greglow.com Reply-To: ozDotNet ozdotnet@ozdotnet.commailto:ozdotnet@ozdotnet.com Date: Sunday, 3 November 2013 10:33 pm To: ozDotNet ozdotnet@ozdotnet.commailto:ozdotnet@ozdotnet.com Subject: Basic MVC4 question on Form Post Hi Folks, I’m still getting my head around MVC4 bit by bit. A quick question if I can: If I have a form declared: @using (Html.BeginForm(SomeAction, SomeController”, FormMethod.Post)) { } I would normally just post it by using an input button set to submit. However, if I don’t want to use a button but want to make the form post when someone clicks on some text in a div contained in the form, how do you do that? Do you have to make an onclick for the div execute some java to post the form? If so, how would you select the form using jQuery in this case? (If I code forms myself, I can give them a name but this Html helper doesn’t seem to have a name). Thanks! (I’ll be back to databases where I know what I’m doing soon :)) Regards, Greg Dr Greg Low CEO and Principal Mentor SQL Down Under SQL Server MVP and Microsoft Regional Director 1300SQLSQL (1300 775 775) office | +61 419201410 mobile│ +61 3 8676 4913 fax Web: www.sqldownunder.comhttp://www.sqldownunder.com/
RE: Basic MVC4 question on Form Post
Add an id to your BeginForm statement, in case you have a second form to the page (there's usually a separate form tag for logout button, if I recall correctly.) using (Html.BeginForm(foo, bar, FormMethod.Post, new { id = myID })) You need to add a click handler to the span containing the text and then perform a form submit there, referencing the id tag. You can add the click handler in the document.ready. $(document).ready(function () { $('body').on('click', '#mySpanId', function () { $(form#myID).submit(); }); This is off the top of my head and is only one possible solution. You might need to check the syntax. From: ozdotnet-boun...@ozdotnet.com [mailto:ozdotnet-boun...@ozdotnet.com] On Behalf Of GregAtGregLowDotCom Sent: Monday, 4 November 2013 4:33 PM To: ozDotNet Subject: Basic MVC4 question on Form Post Hi Folks, I'm still getting my head around MVC4 bit by bit. A quick question if I can: If I have a form declared: @using (Html.BeginForm(SomeAction, SomeController, FormMethod.Post)) { } I would normally just post it by using an input button set to submit. However, if I don't want to use a button but want to make the form post when someone clicks on some text in a div contained in the form, how do you do that? Do you have to make an onclick for the div execute some java to post the form? If so, how would you select the form using jQuery in this case? (If I code forms myself, I can give them a name but this Html helper doesn't seem to have a name). Thanks! (I'll be back to databases where I know what I'm doing soon :)) Regards, Greg Dr Greg Low CEO and Principal Mentor SQL Down Under SQL Server MVP and Microsoft Regional Director 1300SQLSQL (1300 775 775) office | +61 419201410 mobile│ +61 3 8676 4913 fax Web: http://www.sqldownunder.com/ www.sqldownunder.com
Re: Basic MVC4 question on Form Post
Correction.. From: Jorke Odolphi jo...@jorke.netmailto:jo...@jorke.net Reply-To: ozDotNet ozdotnet@ozdotnet.commailto:ozdotnet@ozdotnet.com Date: Sunday, 3 November 2013 10:47 pm To: ozDotNet ozdotnet@ozdotnet.commailto:ozdotnet@ozdotnet.com Subject: Re: Basic MVC4 question on Form Post I’m guessing, something like will get you close. $('div').click( function () { $('form[action=SomeAction]').submit() }) I hope the action is unique enough I don’t know how mvc renders them now.. From: Greg Low g...@greglow.commailto:g...@greglow.com Reply-To: ozDotNet ozdotnet@ozdotnet.commailto:ozdotnet@ozdotnet.com Date: Sunday, 3 November 2013 10:33 pm To: ozDotNet ozdotnet@ozdotnet.commailto:ozdotnet@ozdotnet.com Subject: Basic MVC4 question on Form Post Hi Folks, I’m still getting my head around MVC4 bit by bit. A quick question if I can: If I have a form declared: @using (Html.BeginForm(SomeAction, SomeController”, FormMethod.Post)) { } I would normally just post it by using an input button set to submit. However, if I don’t want to use a button but want to make the form post when someone clicks on some text in a div contained in the form, how do you do that? Do you have to make an onclick for the div execute some java to post the form? If so, how would you select the form using jQuery in this case? (If I code forms myself, I can give them a name but this Html helper doesn’t seem to have a name). Thanks! (I’ll be back to databases where I know what I’m doing soon :)) Regards, Greg Dr Greg Low CEO and Principal Mentor SQL Down Under SQL Server MVP and Microsoft Regional Director 1300SQLSQL (1300 775 775) office | +61 419201410 mobile│ +61 3 8676 4913 fax Web: www.sqldownunder.comhttp://www.sqldownunder.com/