There isn't a way to do this out of the box. However, it wouldn't be too hard to implement this. You just need an attribute that overrides OnActionExecuting to do the check, then set up some variables in the ViewBag. On the client you need to write js code
to respond to this and display the popup based on the ViewBag value.
I did what you said and I am to the point now where I probably need to start namespacing functions. Is there a better way to do this?
Public Class ConfirmationRequired
Inherits ActionFilterAttribute
Public Overrides Sub OnActionExecuted(filterContext As ActionExecutedContext)
'MyBase.OnActionExecuted(filterContext)
Dim result As ViewResult = CType(filterContext.Result, ViewResult)
result.ViewData("confirmationReqired") = True
End Sub
End Class
view...
@ModelType c
@Code
If ViewData("confirmationReqired") Then
@<script type="text/javascript">
$(function () {
$("#confirmation").dialog({
autoOpen: false,
height: 100,
width: 100,
modal: true,
cache: false,
buttons: {
Cancel: function () {
$(this).dialog("close");
},
Ok: function () {
ConditionMetFormSubmit();
$(this).dialog("close");
}
},
close: function () {
}
});
});
</script>
End If
End Code
<script type="text/javascript" src="@Url.Content("~/c/conditionMetForm.js")"></script>
@Using Html.BeginForm("ConditionMetForm", "Conditions", FormMethod.Post, New With {.id = "fConditionMet"})
End Using
<ConfirmationRequired>
<AjaxOrChildActionOnly()>
<Authorize()>
<HttpGet>
Function ConditionMetForm(ByVal idAs Integer, ByVal cid As Integer) As ActionResult
Dim model = New ConditionStatus(cid, id)
Return View("_form", model)
End Function
Shoot I don't know if I shoud put this in post or something because if my modelstate is not valid then my popup dialog is still there and a mess cometh.
Xequence
Contributor
4313 Points
1528 Posts
modelstate confirmation
Jan 29, 2013 05:24 PM|LINK
Is there a way to decorate a class with an attribute that says something along these lines....
if model state is valid
pop form to confirm
if popform true continue else stop
Credentials
CodeHobo
All-Star
18647 Points
2647 Posts
Re: modelstate confirmation
Jan 29, 2013 05:39 PM|LINK
There isn't a way to do this out of the box. However, it wouldn't be too hard to implement this. You just need an attribute that overrides OnActionExecuting to do the check, then set up some variables in the ViewBag. On the client you need to write js code to respond to this and display the popup based on the ViewBag value.
Blog | Twitter : @Hattan
Xequence
Contributor
4313 Points
1528 Posts
Re: modelstate confirmation
Jan 29, 2013 08:41 PM|LINK
I did what you said and I am to the point now where I probably need to start namespacing functions. Is there a better way to do this?
Public Class ConfirmationRequired Inherits ActionFilterAttribute Public Overrides Sub OnActionExecuted(filterContext As ActionExecutedContext) 'MyBase.OnActionExecuted(filterContext) Dim result As ViewResult = CType(filterContext.Result, ViewResult) result.ViewData("confirmationReqired") = True End Sub End Classview...
@ModelType c @Code If ViewData("confirmationReqired") Then @<script type="text/javascript"> $(function () { $("#confirmation").dialog({ autoOpen: false, height: 100, width: 100, modal: true, cache: false, buttons: { Cancel: function () { $(this).dialog("close"); }, Ok: function () { ConditionMetFormSubmit(); $(this).dialog("close"); } }, close: function () { } }); }); </script> End If End Code <script type="text/javascript" src="@Url.Content("~/c/conditionMetForm.js")"></script> @Using Html.BeginForm("ConditionMetForm", "Conditions", FormMethod.Post, New With {.id = "fConditionMet"}) End Using<ConfirmationRequired> <AjaxOrChildActionOnly()> <Authorize()> <HttpGet> Function ConditionMetForm(ByVal idAs Integer, ByVal cid As Integer) As ActionResult Dim model = New ConditionStatus(cid, id) Return View("_form", model) End FunctionCredentials
Xequence
Contributor
4313 Points
1528 Posts
Re: modelstate confirmation
Jan 29, 2013 09:02 PM|LINK
Shoot I don't know if I shoud put this in post or something because if my modelstate is not valid then my popup dialog is still there and a mess cometh.
Credentials