javascript - How to prevent postback in beginform asp.net mvc -
in view have beginform, has 2 buttons, 1 save , 1 cancel. when save clicked, validates data in form controls both client side , server side , postback controller. problem when click either save or cancel, tries validate data , shows validation summary. want prevent postback , validation when cancel button clicked. in cancel button calling javascript function named cancel() calls window.history.back(-1); still trying postback. following code. if move cancel button out of form, doesn't postback, styling messed want both save , cancel button side side
<div id="updateusercreds" class="items"> @using (html.beginform("savecustomer", "newcustomer")) { <div> @html.labelfor(x => x.address.email) <span> @html.kendo().textboxfor(model => model.address.email) </span> </div> <div> @html.labelfor(x => x.address.company) <span> @html.kendo().textboxfor(model => model.address.company) </span> </div> <div> @html.labelfor(x => x.address.streetaddress1, "street address") <span> @html.kendo().textboxfor(model => model.address.streetaddress1) <br/> @html.kendo().textboxfor(model => model.address.streetaddress2) </span> </div> <div> @html.labelfor(x => x.address.fax) <span> @html.kendo().textboxfor(model => model.address.fax) </span> </div> @html.validationsummary() @html.tradeui().notificationsummary() <div class="tti-actions"> <button type="submit">save</button> <button onclick="javascript:cancel();">cancel</button> </div> } </div>
set button type button
<button type="button" onclick="javascript:cancel();">cancel</button>
Comments
Post a Comment