2010-08-25 64 views

回答

2

控制器:

public class TestController : Controller 
{ 
    public ActionResult Test(Test input) 
    { 
     string selected = input.YourDropDown; //Here is your value 

     return View(); 
    } 

} 

型号:

public class Test 
{ 
    public string YourDropDown { get; set; } 
} 

查看:

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<###NAMESPACE###.Models.Test>" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml" > 
<head runat="server"> 
    <title>Test</title> 
</head> 
<body> 
    <div> 
     <% using (Html.BeginForm()) { %> 
      <%= Html.DropDownListFor(model => model.YourDropDown, new[] { new SelectListItem { Text = "Test", Value = "Value" }}) %> 
      <input type="submit" /> 
     <% } %> 
    </div> 
</body> 
</html> 

把视图的文件夹中,如: /Views/Test/Test.aspx

和你的网址是:

url/Test/Test

这将是正确的更好,扩展性最强的一种方式,做你什么。您可以避免制作模型类,并使用Html.DropDownList而不是Html.DropDownListFor

相关问题