将值从下拉列表传递到mvc3中的控制器

将值从下拉列表传递到mvc3中的控制器

本文介绍了将值从下拉列表传递到mvc3中的控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我是MVC3的新手,以前从未从事过MVC.因此需要一些帮助.

我的视图中有下拉菜单.我想将下拉值传递给 controller .

我该如何实现?

下面是视图

Hi,

I am new to MVC3 and i have never worked on MVC before. So need some help.

I am having dropdown in my view. I want to pass dropdown value to controller.

How can i achieve it?

Below is the view

<div class="editor-label">
           Car Model:
           <select id="CarModel" name="CarModel">
               <option>Select Category</option>
           </select>
       </div>



由于某些原因,我想使用 select 作为下拉列表,而不是 @ Html.Dropdownlist @ Html.Dropdownlistfor

谁能为我提供解决方案,关于如何将上述下拉列表的值传递给控制器​​?

提前谢谢.

问候,



By some reason, I want to use select as the dropdown list instead of @Html.Dropdownlist or @Html.Dropdownlistfor

Can anyone suggest me the solution for the same, on how to pass value of the above dropdown list to controller?

Thanks in advance.

Regards,

推荐答案

@using (Html.BeginForm())
{
    <select id="CarModel" name="CarModel">
        <option>Select Category</option>
        <option value="1">one</option>
        <option value="2">two</option>
        <option value="3">three</option>
        <option value="4">four</option>
    </select>

    <br />

    <input type="submit" value="Submit" />
}

@if (ViewData["Data"] != null)
{
    <h1>@ViewData["Data"].ToString()</h1>
}



控制器:



Controller:

public ActionResult Dropdown()
{
    return View();
}

[HttpPost]
public ActionResult Dropdown(string CarModel)
{
    ViewData["Data"] = CarModel;
    return View();
}



希望这会有所帮助!



Hope this helps!


这篇关于将值从下拉列表传递到mvc3中的控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 22:05