Simple JQuery Onclick within Visual Studio

I wanted to perform what I thought would be a simple task..

Select a Radio button and make this perform its task without submitting the form with an extra click on a button.

After much searching and trial and error I found that this task can be done with a simple extension to the radio button:

onClick = "$(this).closest('form').submit();"

Here it is in context:

@Html.Label("Student")

@Html.RadioButtonFor(model => model.RequiredFilter, "Student", new { @class = "radioAlignLeft", onClick = "$(this).closest('form').submit();" })

Hope it helps, if I had found this blog post it would have helped me!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s