C# 如何通过JSon提交带Diactionaries ViewModel的模态对话框
我试图提交一个模态对话框,并在模态消失后在后面的页面上获得结果 我的视图模型----C# 如何通过JSon提交带Diactionaries ViewModel的模态对话框,c#,javascript,jquery,asp.net-mvc,json,C#,Javascript,Jquery,Asp.net Mvc,Json,我试图提交一个模态对话框,并在模态消失后在后面的页面上获得结果 我的视图模型---- 公共类InsertPoStep3 { 公共字典FixedCategoryList{get;set;} 公共字符串说明{get;set;} 公共字典FixedDateRangeList{get;set;} } 如果我按下submit按钮,viewmodel将与字典一起提交给Controller ActionResult 控制器操作结果------ public ActionResult CreateCatego
公共类InsertPoStep3
{
公共字典FixedCategoryList{get;set;}
公共字符串说明{get;set;}
公共字典FixedDateRangeList{get;set;}
}
如果我按下submit按钮,viewmodel将与字典一起提交给Controller ActionResult
控制器操作结果------
public ActionResult CreateCategory(InsertPoStep3 InsertPoStep3)
{
//foreach(formCollection中的var数据)
// {
var fixedCategory=insertPoStep3.FixedCategoryList.Values;
//var description=formCollection[formCollection.Count-1];
var类别=新类别
{
//CategoryId=_db.Categories.Count()+1,
//CategoryDescription=说明,
FixedCategoryId=转换为32(fixedCategory),
};
//_db.Categories.Add(类别);
//_db.SaveChanges();
/*对于(int i=1;i您太难了。ASP.NET MVC具有内置的ajax功能。您要做的是将主页上的按钮链接到部分视图。如果用户单击按钮,将弹出一个模式来加载部分视图。在部分视图中,使用ajax.BeginForm()处理回发到服务器的操作。真的很简单。我知道,因为我刚刚创建了一堆使用模式弹出窗口插入和更新视图模型的页面。hey Sujit……。告诉我这些代码的输出成功:函数(学生){alert(学生);出错…未正确执行成功显示post方法的代码。
public class InsertPoStep3
{
public Dictionary<int, string> FixedCategoryList { get; set; }
public string Description { get; set; }
public Dictionary<int, string> FixedDateRangeList { get; set; }
}
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);
}
<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>