我對C#相當陌生,並且正在創建我的第一個MVC項目,並且很難弄清楚將3個不同類型的參數傳遞給控制器動作。這裏是我的控制器方法:將混合:list <>,對象和原語傳遞給一個ASP MVC控制器動作的方法論
public ActionResult Create(Notification notification, string hash, list<int> users){
//code inside method irrelevant...
}
和我的通知模型:
public class Notification
{
public int ID { get; set; }
public string ApplicationID { get; set; }
public string Description { get; set; }
public System.DateTime DateStamp { get; set; }
}
之前我加入了名單<>參數它好工作由具有發佈的數據(或查詢字符串),像這樣:
ApplicationID=1&Description=yo&hash=abcdefg
它神奇地知道這兩個參數('ApplicationID'和'Description')屬於通知對象。但是現在我想添加一個列表<> ints。
這是可以做的事情,你將如何格式化數據/查詢字符串通過?
[這篇文章](http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx)可能會幫助 –
感謝OP和@Darin Dimitrov!我用這個問題和示例代碼作爲我有一個類似問題的基礎:http://stackoverflow.com/questions/20915681/how-to-pass-a-complex-view-model-into-a-controller-action -via-ajax-call-with-jso – longda