Dear People who type in all lowercase,
We are the difference in helping your Uncle Jack off a horse and helping your uncle jack off a horse.
Sincerely,
Capital Letters
Thursday, February 18, 2016
Wednesday, February 17, 2016
MVC5/Ajax Form Notes
Reference - Ajax Modal Forms in MVC
Requirements
Requirements
- Use Bootstrap Modal: https://getbootstrap.com/javascript/#modals
- Runs client-side, forms rendered on demand, client-side validation
- Use JavaScript to Render Form via Ajax and PartialView into <div>
- Submit Form via JavaScript/Ajax
- Controller validates data with validation client-side
- Create Page with Empty Div to contain modal form
- Create Click Event to Load Form
function openAddressDialog(id) { var data = { Id: id, CompanyId: $('#Id').val() }; $.ajax({ url: '/crm/customer/AddEditAddress/', contentType: 'application/html', data: data, success: function (content) { $('#dialogPlaceholder').html(content); }, error: function (e) { } }); }
- Create Partial View
@model Models.AddEditAddress <div id="dialogResult"></div> @using (Ajax.BeginForm("SaveAddressAjax", "shared", new AjaxOptions { HttpMethod = "POST", InsertionMode = InsertionMode.Replace, OnSuccess = "updateAddressSuccess()", OnFailure = "dialogFailure()", OnBegin = "dialogBegin()", OnComplete = "dialogComplete()", UpdateTargetId = "dialogResult" })) { //… Rest of form code goes here. } <script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script> <script src="~/Scripts/genericDialog.js"></script> <script> $(document).ready(function () { $('#addEditAddressDialog').modal(); }); function updateAddressSuccess() { $('#addEditAddressDialog').modal("hide"); } </script>
Subscribe to:
Posts (Atom)