0
我使用$ HTTP
var registration = {
userId: 23,
groupings: [
{ Id: 1, Name: 'Test Group 1', Description: 'Yo' },
{ Id: 4, Name: 'Test Group 4', Description: 'Er' }
]
}
$http({
method: 'POST',
url: url,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
data: $.param({
code: eventCode,
UserId: registration.userId
Groupings: registration.groupings
})
})
,然後在我的動作有以下POST請求
[HttpPost]
public ActionResult New(string code, RegistrationVM model)
{
:
:
:
}
public class RegistrationVM
{
public int UserId {get;set;}
public IEnumerable<GroupingVM> Groupings { get; set; }
}
public class GroupingVM{
public int Id {get;set;}
public string Name {get;set;}
public string Description {get;set;}
public int AnotherPropertyId {get;set;}
public ANewClass ANewClass {get;set;}
}
每當帖子發生時,我會讓模型屬性反映我發佈的內容,但IEnumerable(分組)屬性除外。比方說,我在Groupings屬性中發佈了2個對象,當我進入Action時,Groupings屬性的計數爲2,但每個實例在每個對象上都有NULL或0值。我試圖弄清楚我是如何搞亂這個帖子的。
不應該的參數是:$ .param({code:eventCode,model:registration}) –
是的,我試過了,它沒有工作。所以,除了代碼,現在一切都是空的。 – gdubs
嘗試並將字符串代碼添加到RegistrationVM類,並在控制器方法中使用一個參數。還要將代碼添加到客戶端的註冊對象中,並傳遞$ .param({model:registration}) –