I'd like to use jQuery's dialog to replace some code I'm using right now within an ASP.NET MVC application. The old code used 'submit' buttons with different 'value' settings. I'd like to know also if there is a better approach.
This is an example of the existing code within the view:
<%using (Html.BeginForm("SubmitValue", "MyController", FormMethod.Post))
{ %>
<span class="field-description">My Value: </span>
<input id="myTextValue" maxlength="6" name="myValue" type="text"/>
<%=Html.Hidden("myModel.myProperty1", Model.PropertyValue1) %>
<%=Html.Hidden("myModel.myProperty2", Model.PropertyValue2) %>
<div class="pageaction button">
<strong>
<input name="submitButton" type="submit" value="Save"/>
</strong>
<strong>
<input name="submitButton" type="submit" value="Delete"/>
</strong>
<strong>
<input type="button" value="Cancel" />
</strong>
</div>
<% } %>
The controller will need the value of the submit button pressed:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult SubmitValue(MyModel model, string submitButton)
{
_request.myProperty1= model.PropertyValue1;
_request.myProperty2= model.PropertyValue2;
if (submitButton == "Save")
{_myService.UpdateValue(_request);}
else
{_myService.DeleteValue(_request);}
return View("MyView", _request);
}
For the jQuery UI, I'd like to use the 'buttons' part of the code to handle the submit values.
$(function() {
$("#dialogWindow").dialog({
bgiframe: true,
autoOpen: false,
height: 200,
modal: true,
open: function(e, ui) {
$("#dialogWindow :input[name='myValue']").val(currentValue);
},
buttons: {
'Save': function() {
// TODO: submit as if a submit button with the value 'Save' is used
$(this).dialog('close');
},
'Delete': function() {
// TODO: submit as if a submit button with the value 'Delete' is used
$(this).dialog('close');
},
Cancel: function() {
$(this).dialog('close');
}
},
close: function() {
//close code
}
});
});