My Dialog Box is an jquery Dialog Box, my popup use <%Html.RenderPartial("MyUC")%> to call an usercontroll for Markup for a Dialog Box. How to the controller can call the value in Dialog Box
If you have a vaule in a TextBox for example there are 2 ways for you to return valuse from the page.
In the Controller request the value specifically.
[AcceptVerbs(HttpVerbs.Post)]
public SomeViewController(string stringValueFromTextBoxOnPartialView){}
The other way to do it is to request the whole form as a FormCollection. This was you can add a fiew input types to your page and you'll only need one object in you're controller.
[AcceptVerbs(HttpVerbs.Post)]
public SomeViewController(FormCollection form){}
More detailed descriptions can be found at http://www.asp.net/learn/mvc/tutorial-33-cs.aspx
Your dialog must contain element, which action url points to YorController/YourAction. Put some with name attribute inside . Then submit the form when dialog "Ok" button is pressed - you'll have passed value in controller.
If your dialog has a form field that wasn't there at the start, i.e. jQuery made it, the you can have your controller ask for it like this
this.Request["jQueryDialogElement"]
or
this.Url.RequestContext.HttpContext.Request["jQueryDialogElement"]
You can put a break point in and see if it is in the QueryString, or Form member of the Request object if you don't know.
It's my dialog code
$(function() {
$("#dialog").dialog({
bgiframe: true,
autoOpen: false,
height: 300,
modal: true,
buttons: {
"Save": function() {
$("#edit").submit();
$('#dialog p').empty();
},
Cancel: function() {
$(this).dialog('close');
$('#dialog p').empty();
}
},
close: function() {
allFields.val('').removeClass('ui-state-error');
}
});
submitHandler: function(form) {
$('#dialog p').append('Click \'OK\' to confirm Edit of <b>$' + $("#Item").val());
$('#dialog').dialog('open');
}
$("input[name=Edit]").click(function() {
var hd = $(this).next(); //will give u hidden div
$("#dialog input[id=ItemId]").val(hd.children("#ItemId").val());
//$("#dialog input[id=CatId]").val(hd.children("#CatId").val());
$("#dialog select > option[id=" + hd.children("#CatId").val() + "]").attr("selected", "selected");
$("#dialog input[id=UnitId]").val(hd.children("#UnitId").val());
$("#dialog input[id=SaleOffId]").val(hd.children("#SaleOffId").val());
$("#dialog input[id=ItemCode]").val(hd.children("#ItemCode").val());
$("#dialog input[id=ItemName]").val(hd.children("#ItemName").val());
$("#dialog input[id=UnitCost]").val(hd.children("#UnitCost").val());
$("#dialog input[id=QuantityRemaining]").val(hd.children("#QuantityRemaining").val());
$("#dialog form").attr("post", "/Item/EditTest/" + hd.children("#ItemId").val(),'json');
alert("/Item/EditTest/" + hd.children("#ItemId").val());
$('#dialog').dialog('open');
})
.hover(
function() {
$(this).addClass("ui-state-hover");
},
function() {
$(this).removeClass("ui-state-hover");
}
).mousedown(function() {
$(this).addClass("ui-state-active");
})
.mouseup(function() {
$(this).removeClass("ui-state-active");
});
});
You can show me i where i wrong? Where I can fix?
Best regards,
Vicky
And This is div contain dialog
<% Html.BeginForm("EditTest", "Item"); %>
<table>
<tr>
<td><b>ItemId</b></td>
<td><input id="ItemId" name="ItemId" type="text" disabled="disabled" /></td>
</tr>
<tr>
<td><b>CatId</b></td>
<td><input id="CatId" name="CatId" type="text" />
<%--<%= Html.DropDownList("CatId", ViewData["AllCategory"] as SelectList)%>--%></td>
</tr>
<tr>
<td><b>SaleOffId</b></td>
<td><input id="SaleOffId" name="SaleOffId" type="text"/></td>
</tr>
<tr>
<td><b>UnitId</b></td>
<td><input id="UnitId" name="UnitId" type="text" /></td>
</tr>
<tr>
<td><b>ItemCode</b></td>
<td><input id="ItemCode" name="ItemCode" type="text" /></td>
</tr>
<tr>
<td><b>ItemName</b></td>
<td><input id="ItemName" name="ItemName" type="text" /></td>
</tr>
<tr>
<td><b>UnitCost</b></td>
<td><input id="UnitCost" name="UnitCost" type="text"/></td>
</tr>
<tr>
<td><b>QuantityRemaining</b></td>
<td><input id="QuantityRemaining" name="QuantityRemaining" type="text"/></td>
</tr>
<tr>
<td><input type="submit" id="Save" name="Save" value="Save" /></td>
<td><input type="submit" id="Cancel" name="Cancel" value="Cancle" onclick="back(-1);" /></td>
</tr>
</table>