0
我的问题是我有一个抽象类,当使用时正确地绑定到页面,但是当我尝试发布模型(基于抽象类的完全形成的类)回到控制器抽象类的属性没有被填充。mvc发布类基于关抽象类
我采取的方法是如下
public abstract class BaseClass
{
private int _property1;
public int Property1
{
get{
return _property1;
}
set{
_property1=value;
}
}
}
public class ImplementClass:BaseClass
{
public ImplementClass()
{
}
}
控制器
public class Ctrler:Controller
{
public ActionResult DoSomthing()
{}
[HTTPPOST]
public ActionResult DoSomthing(ImplementClass model)
{
//...doSomthing with class but the property1 has a value of 0 and debugging will never set the Property on the class
}
}
的看法是
@model ImplementClass
@(using(Html.BeginForm("DoSomthing","Ctrler"), FormMethod.Post, new { @id = "frm1", @enctype = "multipart/form-data" }))
{
<div>
@Html.HiddenFor(x=>x.Property1,new {@Value="1"})
</div>
<input type="Submit" Value="Submit"/>
}
提交是通过Ajax和代码是财产以后像。
$(function(){
$('form').bind('submit',submitForm);
function submitForm()
{
var submitForm = $('form');
var data = submitForm.serializeObject();
$.ajax(submitForm.prop('action'),
{
cached: false,
type: 'POST',
// dataType: 'json',
// contentType: 'application/json; charset=utf-8',
data: data,
success: function (response)
{
alert(response);
}
}
return false;
}
});
[编辑] 我发现这是我自己的愚蠢的问题,我已经在类保护设置。
谢谢,这正是我需要这样的事情。 – Qpirate