I'm pretty much at the point I give up. All I want to do is use the Wizard to load partial views for each step, and all I want to do is prevent the next step if the form can't be validated. I've tried nearly everything for 3 days and I can't seem to find an answer. I've tried jquery..validate and it just goes no where.
I just have a real simple setup, Business.cshtml which contains the wizard
@using Kendo.Mvc.UI
@model Reverberate.BLL.Model.Form.Application.BusinessOnboardingModel
@{
ViewBag.Title = "Business Onboarding";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<style>
.wide {
width: 95%;
}
.field-validation-error {
color: red;
}
</style>
<!-- Wizard -->
@(Html.Kendo().Wizard()
.Name("wizard")
.Events(ev => ev.Select("onSelect"))
.Events(ev => ev.Done("onDone"))
.LoadOnDemand(true)
.ReloadOnSelect(false)
.Steps(s =>
{
s.Add<Reverberate.BLL.Model.Form.Application.BusinessOnboardingModel>()
.Title("Business Profile")
.ContentUrl(Url.Action("_BusinessProfile", "Onboard"))
.Buttons(b =>
{
b.Next().Text("Next");
});
s.Add<Reverberate.BLL.Model.Form.Application.BusinessOnboardingModel>()
.Title("Business Financial")
.ContentUrl(Url.Action("_BusinessFinancial", "Onboard", Model))
.Buttons(b =>
{
b.Previous().Text("Back");
b.Next().Text("Next");
});
s.Add<Reverberate.BLL.Model.Form.Application.BusinessOnboardingModel>()
.Title("Business Address")
.ContentUrl(Url.Action("_BusinessAddress", "Onboard", Model))
.Buttons(b =>
{
b.Previous().Text("Back");
b.Done().Text("Submit");
});
})
)
<script type="text/javascript">
var dataPartial1;
var dataPartial2;
var currentStep;
function onSelect(e) {
var form, contentUrl;
if (e.step.options.index < currentStep) {
e.preventDefault();
}
else {
if (e.step.options.index == 1) {
form = $('#frmPartialBusinessProfilefrmPartialBusinessProfile');
dataPartial1 = form.serialize();
contentUrl = '@Url.Action("_BusinessFinancial", "Onboard",Model)';
}
else if (e.step.options.index == 2) {
form = $('#frmPartial2');
dataLesions = form.serialize();
contentUrl = '@Url.Action("_BusinessAddress", "Onboard",Model)';
}
if (!form.valid()) {
alert('not valid');
e.preventDefault();
}
else {
alert('valid');
e.step.options.contentUrl = contentUrl;
}
alert('done');
}
currentStep = e.step.options.index;
}
function onNextStep(e) {
if (e.step.options.index == 2) {
openDoc();
}
}
function onDone(e) {
var form = $('#frmMain');
if (form.valid()) {
form.submit();
}
}
var onAddMainSuccess = function (result) {
if (result.error) {
alert(result.error);
}
};
</script>
<script src="https://cdn.jsdelivr.net/jquery.validation/1.13.1/jquery.validate.min.js"></script>
and a partial view called _BusinessProfile
@using Kendo.Mvc.UI
@model Reverberate.BLL.Model.Form.Application.BusinessOnboardingModel
<form id="frmPartialBusinessProfile" name="frmPartialBusinessProfile">
<div style="width: 45%; float: left; border: 1px solid black" id="BusinessInfoEntry">
<h3>Business Profile</h3>
<fieldset>
<legend></legend>
<ol>
<li>
@Html.LabelFor(m => m.BusinessProfileModel.BusinessName)
<br />
@Html.TextBoxFor(m => m.BusinessProfileModel.BusinessName, new { maxlength = 200, @class = "wide" })
@Html.ValidationMessageFor(m => m.BusinessProfileModel.BusinessName)
</li>
<li>
@Html.LabelFor(m => m.BusinessProfileModel.FederalTaxId)
<br />
@Html.TextBoxFor(m => m.BusinessProfileModel.FederalTaxId, new { maxlength = 20 })
@Html.ValidationMessageFor(m => m.BusinessProfileModel.FederalTaxId)
</li>
<li>
@Html.LabelFor(m => m.BusinessProfileModel.BusinessStartDate)
<br />
@Html.TextBoxFor(m => m.BusinessProfileModel.BusinessStartDate, new { @type = "date", @class = "form-control datepicker", @Value = Model == null || Model.BusinessProfileModel.BusinessStartDate == null ? null : Model.BusinessProfileModel.BusinessStartDate.ToString("yyyy-MM-dd") })
@Html.ValidationMessageFor(m => m.BusinessProfileModel.BusinessStartDate)
</li>
<li>
@Html.LabelFor(m => m.BusinessProfileModel.Industry)
<br />
@Html.TextBoxFor(m => m.BusinessProfileModel.Industry, new { maxlength = 200, @class = "wide" })
@Html.ValidationMessageFor(m => m.BusinessProfileModel.Industry)
</li>
<li>
@Html.LabelFor(m => m.BusinessProfileModel.Sector)
<br />
@Html.TextBoxFor(m => m.BusinessProfileModel.Sector, new { maxlength = 200, @class = "wide" })
@Html.ValidationMessageFor(m => m.BusinessProfileModel.Sector)
</li>
<li>
@Html.LabelFor(m => m.BusinessProfileModel.StateOfFormation)
<br />
@Html.DropDownListFor(m => m.BusinessProfileModel.StateOfFormation, new SelectList(ViewBag.States, "Value", "Text"), "Select State", htmlAttributes: new { @class = "form-control", id = "StateOfFormationList" })
@Html.ValidationMessageFor(m => m.BusinessProfileModel.StateOfFormation)
</li>
<li>
@Html.LabelFor(m => m.BusinessProfileModel.EmployeeCount)
<br />
@Html.TextBoxFor(m => m.BusinessProfileModel.EmployeeCount, new { @type = "number", @class = "wide" })
@Html.ValidationMessageFor(m => m.BusinessProfileModel.EmployeeCount)
</li>
<li>
@Html.LabelFor(m => m.BusinessProfileModel.BusinessStructure)
<br />
@Html.DropDownListFor(m => m.BusinessProfileModel.BusinessStructure, new SelectList(ViewBag.BusinessTypeList, "Value", "Text"), "Select Business Type", htmlAttributes: new { @class = "form-control", id = "StateOfFormationList" })
@Html.ValidationMessageFor(m => m.BusinessProfileModel.BusinessStructure)
</li>
</ol>
</fieldset>
</div>
</form>
{
public class BusinessOnboardingModel { public BusinessProfileModel BusinessProfileModel { get; set; } public BusinessFinancialModel BusinessFinancialModel { get; set; } } }
and here is the BusinessProfileModel
using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Reverberate.BLL.Model.Form.Application.BusinessOnboarding { public class BusinessProfileModel { public BusinessProfileModel() { } [Required(ErrorMessage = "The business name is required.")] [DisplayName("*Business Name")] [StringLength(250)] public string BusinessName { get; set; } [DisplayName("*Federal Tax Id / SSN")] [StringLength(15, ErrorMessage = "Please enter a valid federal tax id or SSN")] [Required(ErrorMessage = "Please enter the federal tax id or SSN")] public string FederalTaxId { get; set; } [DisplayName("*Business Start Date")] [Required(ErrorMessage = "Please enter the business start date")] public DateTime BusinessStartDate { get; set; } [Required(ErrorMessage = "The industry is required.")] [DisplayName("*Industry")] [StringLength(500)] public string Industry { get; set; } [Required(ErrorMessage = "The sector is required.")] [DisplayName("*Sector")] [StringLength(500)] public string Sector { get; set; } [DisplayName("*State of Formation")] [Validation.InputValidation.ValidState(ErrorMessage = "This does not appear to be a valid US State.")] [Required(ErrorMessage = "The State of Formation is required.")] public string StateOfFormation { get; set; } [DisplayName("*No of Employees")] [Validation.InputValidation.ValidState(ErrorMessage = "Number of Employees.")] [Required(ErrorMessage = "Please Supply the number of employees.")] public int EmployeeCount { get; set; } [Validation.InputValidation.ValidBusinessType(ErrorMessage = "Please enter a valid business structure")] [Required(ErrorMessage = "The business structure required.")] [DisplayName("*Business Structure")] public string BusinessStructure { get; set; } } }
Thank you for sharing these details. I am glad to hear that the desired result is now achieved.
Best Regards,
Anton Mironov