programmer138200 programmer138200 - 1 year ago 133
jQuery Question

How to bind click event of button into PartialView (MVC)?

I make a page in MVC .In this page exist a View and a PartialView.I put button into partialview and write Countinue function into View.


<button type="button" class="btn btn-warning center-block btn-large" id="Continue" onclick="Continue(this);">Continue</button>


var Continue=function (e) {
if ($('#FieldsetCharterFlightsReturn article').size() < 1) {
if (validateDeparturef(e)) {

if ($('#FieldsetCharterFlightsReturn article').size() > 0) {
if (validateDeparturef(e) && validateArrivalf(e)) {

Now When i click on the button get this error:

TypeError: Continue is not a function

What is right way to bind event of elements into PartialView?

Answer Source

Since you are using bind event using it instead of ugly-inline click handler.

    $('#Continue').on('click', Continue);

OR, Using Event delegation

 $(document).on('click', '#Continue', Continue);

And remove inline onclick="Continue(event);" handler

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download