【发布时间】:2020-04-03 00:53:02
【问题描述】:
我正在尝试将复杂对象从视图发送到控制器。该对象由 html 表中的对象组成。 当我通过 AJAX 调用调用控制器时,对象列表始终为空。我不知道出了什么问题,因为我检查了互联网上的其他代码,我没有发现任何区别,但必须有一些东西。提前致谢。
型号
public class Parameter
{
public string Name { get; set; }
public string ControlType { get; set; }
public string ToolTip { get; set; }
public List<string> CheckedControl { get; set; }
public int GroupID { get; set; }
public int CtrIndex { get; set; }
public List<string> DdItems { get; set; }
public List<string> LangList { get; set; }
public List<string> DdMulti { get; set; }
}
Javascript 和 ajax
function ajaxSubmit() {
var table_parameters = [[],[]];
table_parameters = getSchemaTableData();
var projectName = document.getElementById('txtProjectName').value;
var projectID = document.getElementById('txtProjectID').value;
jQuery.ajax({
type: "POST",
url: "@Url.Action("ControlsCreation", "Projects")",
dataType: "json",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({ Parameters: table_parameters, ProjectName: projectName, ProjectID: projectID }),
success: function (data) { alert(data); },
failure: function (errMsg) {
alert(errMsg);
}
});
}
和控制器
public JsonResult ControlsCreation(List<Models.Parameter> Parameters, string ProjectName, string ProjectID)
{
if (Session["UserID"] == null) return Json("Home/Index");
string userID = Session["UserID"] as string;
var mngService = new DBManager(ConfigurationManager.ConnectionStrings["Bugmania2019"].ConnectionString);
DBLogic dbAccess = new DBLogic(mngService);
ViewModels.ParametersTable viewModel = new ViewModels.ParametersTable()
{
ParametersCollection = Parameters,
ProjectName = ProjectName,
ProjectID = ProjectID
};
dbAccess.UpdateControls(viewModel);
return Json("Success!");
}
我已经修改了控制器、视图和模型。我将不胜感激任何帮助。谢谢
【问题讨论】:
标签: c# html-table asp.net-mvc-5