Click here to Skip to main content
15,890,185 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I have design the MVC form which contains some fields. I want to throw confirmation box before submitting information. But in my case if I fill invalid data and press SUBMIT button it is showing confirmation box first and then shows the validation.

I want to show the validations before the confirmation box. Once all the fields are validated then only it should ask for confirmation.

I am attaching the chtml code for the reference...............

What I have tried:

@model SECU_CAMSPlus_DEV.Models.Manufacturer

@{
ViewBag.Title = "EditManufacturer";
Layout = null;
}

@if (TempData["invalidmsg"] != null)
{
<script> $("#divinvalid").show();
$("#btnRefresh").hide(); </script>
}
@if (TempData["notice"] != null)
{
<script> $("#divSuccess").show(); $("#btnRefresh").hide(); </script>
}

<script language="javascript" type="text/javascript">
function varcharonly(evt)
{
var e = evt
if (window.event) { //IE
var ascii = e.keyCode;
}
else if (e.which) { // Safari 4, Firefox 3.0.4
var ascii = e.which
}
if ((ascii == 8 || ascii == 127) || (ascii > 64 && ascii < 91) || (ascii > 96 && ascii < 123) || (ascii == 32 || ascii == 44 || ascii == 45 || ascii == 95 || ascii == 46 || ascii == 47) || (ascii > 47 && ascii < 58)) {
return true;
}
else {
return false;
}
}
function charonly() {
var ascii = event.keyCode
if ((ascii == 8 || ascii == 127) || (ascii > 64 && ascii < 91) || (ascii > 96 && ascii < 123) || (ascii == 32) || (ascii == 38)) {
event.returnValue = true;
}
else {
event.returnValue = false;
}
}
function IsValidCompanyName()
{
$("#errorInValidCompanyName").html('');
var pwdreg = /^[a-zA-Z ]+$/;
var pwdval = $("#txtCompanyName").val();
if (!pwdreg.test(pwdval)) {
$("#txtCompanyName").after('Use Alphabets only');
$('#btnaddManufacturer').attr('disabled', true);
}
else {
$("#errorInValidCompanyName").html('');
$('#btnaddManufacturer').attr('disabled', false);
}
}
function setValue()
{
$("#errorInValidCompanyName").remove();
$('#btnaddManufacturer').attr('disabled', false);
}

</script>

@*<script>
$("#SelectedWidgetId").on("change", function () {
$("#SelectedWidgetId option:selected").text();
$('#costLabel').text('Total price: ' + newText);
console.log($("#SelectedWidgetId").val());
});
</script>*@





@using (Html.BeginForm("Create", "Manufacturer", FormMethod.Post, new { @id = "ManufacturerMasterCreate" }))
{ @Html.ValidationSummary(false, null, htmlAttributes: new { @class = "valiation" })
@Html.AntiForgeryToken()



}




[Required]
[Display(Name = "Company Name *")]
public string CompanyName
{
get { return _CompanyName; }
set { _CompanyName = value; }
}

[Required]
[Display(Name = "Device Name *")]
public string DeviceTypeName
{
get { return _DeviceTypeName; }
set { _DeviceTypeName = value; }
}
Posted
Updated 19-Apr-16 20:34pm
v2
Comments
Sergey Alexandrovich Kryukov 20-Apr-16 4:26am    
Do you have something like Submit button, or some other element like that? For a button, handle onclick. Apparently, the JavaScript handler comes before the post...
If you already to that, then what's the problem?
—SA
chathuranga abeyrathne 22-Apr-16 5:21am    
this is tightly cuppled a Manufacturer model than and use dataannotations attribute to validate the model it will validate the error data after that submit button will fire the script

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900