Thanks, i had definitely thought about going that route. However my partial view contains dynamic data and a varying length of textbox fields depending on the selections. I havent been able to figure out a way to get that data without using jquery.
So far what i have done is use jquery to post the whole form to a controller with my new ViewModel which works fine. I can see all the right data when it hits the controller.
But now my concern is what do i wire this up to? If i wire it up to a submit button inside a form then i need to add a controller and action (which it shouldnt hit). it seems that the action will execute as well as the ajax request which is exactly what i dont want. If i wire it up to a regular button with just an onClick then i lose my client side validation. Is there a way to call the client side validation manually? Here is the ajax post,
function saveFormData() {
var equipDatas = new Array();
var customPropertyList = new Array();
equipDatas = {
equipmentType_ID: 1,
SerialNumber: 1,
Manufacturer_ID: 1,
BusinessUnit_ID: 1,
CurrentStatus_ID: 1
};
for (var i = 0; i < $("input:text[name^=txt]").length; i++) {
customPropertyList[i] = {
equipment_ID: 1,
customPropertyName_ID: $("#Hidden" + i).val(),
Value: $("#txt" + i).val()
};
}
var url = '@Url.Action("DummyCreate")';
$.ajax({
type: "POST",
url: url,
contentType: "application/json; charset=utf-8",
data: JSON.stringify({ equip: equipDatas, custData: customPropertyList }),
datatype: "JSON"
});
}
alm1
Member
133 Points
60 Posts
Re: Posting data with returned ID from controller
Mar 01, 2012 01:04 AM|LINK
Thanks, i had definitely thought about going that route. However my partial view contains dynamic data and a varying length of textbox fields depending on the selections. I havent been able to figure out a way to get that data without using jquery.
So far what i have done is use jquery to post the whole form to a controller with my new ViewModel which works fine. I can see all the right data when it hits the controller.
public ViewResult dummyCreate(ZITS_DAL.Equipment equip, List< ZITS_BO.boCustomProperties.ajaxPostData> custData) { return View(equip); }But now my concern is what do i wire this up to? If i wire it up to a submit button inside a form then i need to add a controller and action (which it shouldnt hit). it seems that the action will execute as well as the ajax request which is exactly what i dont want. If i wire it up to a regular button with just an onClick then i lose my client side validation. Is there a way to call the client side validation manually? Here is the ajax post,
function saveFormData() { var equipDatas = new Array(); var customPropertyList = new Array(); equipDatas = { equipmentType_ID: 1, SerialNumber: 1, Manufacturer_ID: 1, BusinessUnit_ID: 1, CurrentStatus_ID: 1 }; for (var i = 0; i < $("input:text[name^=txt]").length; i++) { customPropertyList[i] = { equipment_ID: 1, customPropertyName_ID: $("#Hidden" + i).val(), Value: $("#txt" + i).val() }; } var url = '@Url.Action("DummyCreate")'; $.ajax({ type: "POST", url: url, contentType: "application/json; charset=utf-8", data: JSON.stringify({ equip: equipDatas, custData: customPropertyList }), datatype: "JSON" }); }Thanks Andy