MVC4 Razor如何从下拉列表中获取选定的值?

时间:2014-09-12 11:04:05

标签: razor html.dropdownlistfor

我的模特:

  namespace mvc4deneme.Models
 {

public class SiparisModel
{
    public string SelectedValue { get; set; }
    public IEnumerable<SelectListItem> Values { get; set; }


    [Display(Name = "Ürün Tipi")]
    public Material UrunTipi { get; set; }

    [Display(Name = "Yüzey")]
    public Material Yuzey { get; set; }


 public class Material
    {

        //public int? ID { get; set; }
        public string ID { get; set; }
        public string Name { get; set; }
    }
  }

我的控制者:

//我的控制页面是SiparisController

  public class SiparisController : Controller
{
    //
    // GET: /Siparis/

    public ActionResult Index()
    {
        DataTable dt = null;
        Material material = null;
        var model = new SiparisModel();


        List<Material> lstYuzey = new List<Material>{

            new Material { ID = null, Name = "Seçiniz" }, 
            new Material { ID = "D/-", Name = "Tek Yüz" }, 
            new Material { ID = "D/D", Name = "Çift Yüz" } };
        ViewBag.Yuzey = lstYuzey;

        List<Material> lstUrunTipi = new List<Material>  {

            new Material { ID = null, Name = "Seçiniz" }, 
            new Material { ID = "3100140", Name = "MKYL" }, 
            new Material { ID = "3100180", Name = "FS.MKYL FA" },
            new Material { ID = "3100190", Name = "FS.MKYL FC" }, 
            new Material { ID = "3100090", Name = "YL" }, };
        ViewBag.UrunTipi = lstUrunTipi;
      return View(model);

          }
           }

MY Index.cshtml查看页面:

@using (Html.BeginForm())
{
    @Html.DropDownListFor(x => x.SelectedValue, Model.Values)
    <button type="submit">OK</button>
    @Html.LabelFor(m => m.UrunTipi) 
    @Html.DropDownListFor(m => m.UrunTipi.ID, 
           new SelectList(ViewBag.UrunTipi, "ID", "Name"), 
           new { style = "width:310px" }) 
    @Html.ValidationMessageFor(m => m.UrunTipi.ID) }    

    @using (Html.BeginForm())
       {
           @Html.LabelFor(m => m.Yuzey) 
           @Html.DropDownListFor(m => m.Yuzey.ID, 
               new SelectList( ViewBag.Yuzey,"ID", "Name"), 
               new { style =  "width:310px" })
           @Html.ValidationMessageFor(m => m.Yuzey.ID) 
       }    

我的要求: 如何执行ok按钮获取我的UrunTipi和Yuzey选定值的值。

非常感谢你。

此致 B.Y。

0 个答案:

没有答案