私の MVC アプリケーションでは、次のような ViewModel を定義しました。
public class TestModel : Test
{
public TestModel (Models.Test1 t1)
:base(t1)
{ }
public TestModel (Models.Test1 t1, Models.Test1 t2)
:base(t1,t2)
{ }
クラス Test は次のように定義されます。
public class Test
{
public Test(Models.Test1 t1)
{
//set the properties for t1
}
public Test(Models.Test1 t1, Models.Test1 t2)
:this(t1)
{
//set properties for t2
}
}
// properties for t1 and t2
}
私のビューでは TestModel を使用して、t1 と t2 のフィールドを組み合わせて表示します。このようなフォームを送信すると:
$('form').submit(function (evt) {
Save($(this).serialize(),
function () {
$('.loading').show();
},
function () {
alert('success');
});
});
$('a.save').click(function (evt) {
$(this).parents('form').submit();
});
- the controller action below is never hit.
[HttpPost]
public JsonResult Save(TestModel camp)
{
Helper.Save(camp);
return Json(JsonEnvelope.Success());
}
TestModel は Test から派生しているため、シリアル化が機能していないと思います。これを機能させる方法に関する提案はありますか?