It really depends on what the warning is for, is the warning checking for something or is the warning always there by default?
If it is always there by default the easiest solution would be to have the warning appear via some jquery the first time where a fake submit button is pressed and have the actual submission button enabled and appear when the warning appears with the fake button disappearing. So on the page in the html hide and disable the submit button with display: none and disabled initially and place a fake button in the same place, then something like this in the js:
$('#yourformidhere').submit(function () {
$('#fakesubmitbutton').hide();
$('#realsubmitbutton'.show();
$(this).find(':submit').prop('disabled', 'false');
});
If you have to check something server side then you need to return the page and model via the controller. On the page use a hidden marker set to say '1' and then in the controller perform the check and return the page if the check fails with the model field with the marker changed to '2' along with the warning. The user can then submit the form again, your controller action checks for the '2' and if it finds it allows for submission of the form without the check.
Edit - An example:
A form:
@using (Html.BeginForm()){
@Html.Hiddenfor(model => model.hidden)
@Html.EditorFor(model = model.data1)
<input type ="submit" value"submit"/>
}
Viewmodel:
public class someviewmodel{
public string data1 { get; set; }
public int hidden { get; set; }
}
Controller
public ActionResult forumsubmit(someviewmodel model)
{
//check to see if this is the first submission attempt
if (model.hidden == null){
//check for whatever you need regarding the warning e.g.
if (model.data1 == needswarning){
//add your warning message here if it is to appear on the page for example a viewbag
ViewBag.warning = "you've been warned"
//change hidden field to 1 to acknowledge first submission attempt
model.hidden = 1;
//returns view with information intact for second submission
return View(model);
}
}
//if you reach here in the controller action the hidden field is either not null or there is no need for a warning so you can now process the form and add info to db here.
return View("submitsuccess")
}