にリストを渡すと、これは、ビューからコントローラにデータを渡すために、私のjavascript関数である:form.serialize
function UpdateCourse() {
debugger
SelectedIncharge();
SelectedAssistants();
SelectedParticipants();
var Course = $("form").serialize();
var model = {
courseData: Course,
SelectedInchargeList: SelectedInchargeList,
SelectedAssistantList: SelectedAssistantList,
SelectedParticipantList: SelectedParticipantList
};
debugger
$.ajax({
url: '@Url.Action("UpdateCourseDetails", "Course")',
type: 'POST',
dataType: 'JSON',
data: model,
// contentType: "application/json",
success: function (data) {
$('#CoursesSaveBtn').prop("disabled", false);
ShowStatus(data.Response);
hideWait();
GetCourseGrid();
},
error: function (xhr) {
$('#CoursesSaveBtn').prop("disabled", false);
var response = { "ResponseCode": 99, "ResponseMessage": "Validation Failed" };
var responseCode = JSON.parse(JSON.stringify(response));
ShowStatus(responseCode);
hideWait();
}
});
}
私はモデル変数の値を取得していますが、私は正しくcourseDataがnullのままリストのみを取得します。ここに私のビューモデルのコードです。
public class CourseModel
{
//public Guid Id { get; set; }
//public string Name { get; set; }
//public string Description { get; set; }
//public string ClassRoom { get; set; }
//public DatabaseOperationType Operation { get; set; }
public CourseRequestDto courseData { get; set; }
public List<Guid> SelectedInchargeList { get; set; }
public List<Guid> SelectedAssistantList { get; set; }
public List<Guid> SelectedParticipantList { get; set; }
}
そして、私のコントローラの定義は次のとおりです。
[HttpPost]
public ActionResult UpdateCourseDetails(CourseModel model)
{
}
var course = $( "form")。serialize(); 'フォームをシリアル化します(クエリ文字列を作成します)。そのデータを含む別のオブジェクトを作成することはできません。生成したものが正しく表示されていれば、 '.serialize()'はあなたのコレクションを含むすべてのデータを送信するために必要なものです。そして、あなたは 'SelectedInchargeList'などのあなたの変数が何であるか私たちに語っていません。 –