2016-04-11 34 views
0

以下のようなドロップダウンリストがあります。データはビューバックを使用してバインドされます。mvcのドロップダウンリストから選択した値を取得する方法C#

<div class="col-md-4"> 
    <h2 style="color: #2f6207">dfdfDestination</h2> 
    @Html.DropDownList("Destination", new SelectList(ViewBag.Destination, "regCde", "Destination", "Destination")) 
</div> 

ここで、ドロップダウンリストから選択した値を特定のコントローラに送信します。私はこれを行うためにjQueryとajaxを使用します。値を送信します。しかし、クエリの値はnullになります。何も思いつきません。これを行う他の方法はありますか?

public ActionResult MscHome(string mydestination) 
{ 
    return View(); 
} 

答えて

1

ビュー:

@using (Html.BeginForm("MscHome", "Home", FormMethod.Get)) 
{ 
    <div class="col-md-4"> 
     <h2 style="color: #2f6207">dfdfDestination</h2> 
     @Html.DropDownList("Destination", new SelectList(ViewBag.Destination, "regCde", "Destination", "Destination")) 

    </div> 
    <p> 
     <input type="submit" value="Submit" /> 
    </p> 

} 

コントローラー:ビューを実行する場所を知っているので、あなたがHtml.BeginForm上のアクションとコントローラを指定する必要が

public ActionResult MscHome(string Destination) 
{ 
    return View(); 
} 

お知らせHTTPGETまたはHttpPostドロップダウンリストの値の名前は、コントローラー内のアクション結果のパラメーター名と同じである必要があります。

+0

もちろん、あなたがすでに知っていると思う提出ボタンを追加する必要があります。 –

+0

それを追加する方法を教えてください。私はこれを確認することができます – bill

+0

仕事は、それは働いています。 – bill

関連する問題