我有View Model,如下所示:
public class ViewModel {
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public string Description { get; set; }
}
根据我的要求,不需要标签。我只需要设置其他服务器端数据。所以我试图在按钮标签中初始化数据属性,如:
@model ViewModel
<form>
@if(someCondition){
<button data-model="{StartDate='*true logic value*',EndDate='*true logic value*',Description='*true logic value*'}" class="form-submit">
submit
</button>
} else{
<button data-model="{StartDate='*false logic value*',EndDate='*false logic value*',Description='*false logic value*'}" class="form-submit">
submit
</button>
}
</form>
$('.form-submit').click(function() {
var departure = $(this).data('model');
var parsedData = JSON.parse(JSON.stringify(departure));
$.ajax({
type: "POST",
url: "//some Url",
data: parsedData,
success: function(response) {}
});
});
但是当它被提交时,在Controller View模型中,数据将变为空值。
我错了什么?