2011-12-10 35 views

回答

2

下面是如何在複選框的情況下完成這個例子。請注意,在GET請求的情況下,您不會看到重複的相同查詢字符串參數。相反,如果選中複選框1和3,則會看到「?metros = 1,3」。

HTML

<form action="http://site.com/directory" method="get"> 
    <input type='checkbox' name='metros' value='1' /> 
    <input type='checkbox' name='metros' value='2' /> 
    <input type='checkbox' name='metros' value='3' /> 
</form> 

控制器

public class DirectoryController : Controller { 
    public ActionResult Index(IEnumerable<int> metros) { 
     foreach (var metro in metros) { 
      // do something 
     } 

     return View(); 
    } 
} 
+0

我改變你的操作方法的最後一行:'返回查看(地鐵)'。所以,我得到理想的網站site.com?metros=2&metros=3。它工作正常!非常感謝你! – greatromul

相關問題