我正在尝试提交一个模态对话框并在模态消失后在后页上获取结果。
我的视图模型----
public class InsertPoStep3
{
public Dictionary<int, string> FixedCategoryList { get; set; }
public string Description { get; set; }
public Dictionary<int, string> FixedDateRangeList { get; set; }
}
如果我按下提交按钮,该视图模型将与字典一起提交给控制器 ActionResult
控制器动作结果------
public ActionResult CreateCategory(InsertPoStep3 insertPoStep3)
{
// foreach (var data in formCollection)
// {
var fixedCategory = insertPoStep3.FixedCategoryList.Values;
//var description = formCollection[formCollection.Count - 1];
var category = new Category
{
//CategoryId = _db.Categories.Count() + 1,
//CategoryDescription = description,
FixedCategoryId = Convert.ToInt32(fixedCategory),
};
//_db.Categories.Add(category);
// _db.SaveChanges();
/* for(int i=1;i<formCollection.Count-1;i++)
{
_db.DateRanges.Add(new DateRange
{
CategoryId = category.CategoryId,
FixedDateRangeId = Convert.ToInt32(formCollection[i])
});
}
_db.SaveChanges();*/
return Json(insertPoStep3);
}
评论太多了...实际上我不知道如何使用字典从视图模型中获取数据...。
我的模态对话框 JavaScript--------
<script type="text/javascript">
$(function () {
$("#InsertCategoryAnchor").click(function () {
$("#form-dialog").load("/InsertPo/CreateCategory");
$("#form-dialog").dialog({
modal: true,
height:500,
width: 700,
closeOnEscape: true,
resizable: false,
draggable: true,
title: "Insert a Category",
close: function(){
$(this).dialog("destroy");
},
buttons: {
Submit: function () {
var value = $("#myfrom").serialize();
$.ajax({
url: "/InsertPo/CreateCategory",
type: "POST",
data: value,
success: function (student) {
alert("Yes");
$(this).dialog('close');
}
});
},
Cancel: function () {
$(this).dialog("destroy");
}
}
});
});
});
</script>
实际代码将如何???请任何人一步一步回答......我正在修复......代码和场景在这里......但它不起作用...... JSon和字典......