ASP.NET MVCアプリケーション内で現在使用しているコードをjQueryのダイアログを使用して置き換えたいと思います。古いコードでは、さまざまな '値'設定の「送信」ボタンが使用されていました。より良いアプローチがあるかどうかも知りたいです。私がしたい、jQueryのUIについては異なる値のボタンを使用してjQueryダイアログを使用してサブミットする方法
[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);
}
を:コントローラが押された送信ボタンの値が必要になります
<%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>
<% } %>
:
これは、ビュー内の既存のコードの例です。サブミット値を処理するためにコードの 'ボタン'部分を使用するのが好きです。
$(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
}
});
});