2013-05-07 65 views
2

我想將URL中的字符串aray傳遞給mvc控制器。ASP MVC - 在參數模型中調用帶有列表的控制器

我控制器的方法是

public ActionResult Index(MyModel model) 

,我想我的模型是

public class TagEditRequestVM 
{ 
    public string ValueA { get; set; } 

    public List<string> MyList { get; set; } 
} 

什麼是最好的URL結構來調用它?

+1

看看這裏:HTTP:// WWW .hanselman.com /博客/ ASPNETWireFormatForModelBindingToArraysListsCollectionsDictionaries.aspx – 2013-05-07 07:47:32

回答

3

你必須使用一個索引和[] -notation:

http://host/Controller/Index?ValueA=val&MyList[0]=item1&MyList[1]=item2 

該指數已經不成爲一個遞增的整數 - 它只是必須是唯一的。

編輯

好,感謝鏈接plurby在他的評論中寫道,你可以離開了括號標記和重複剛纔的屬性名稱:

http://host/Controller/Index?ValueA=val&MyList=item1&MyList=item2 
相關問題