在下拉单击时渲染部分视图 [英] Render a partial view upon drop down click

查看:83
本文介绍了在下拉单击时渲染部分视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一定数值的下拉菜单



 @ using(Html.BeginForm())
{

@ Html.DropDownList( 动物类型
< span class =code-keyword> new SelectList((System.Collections.IEnumerable)ViewData [ Animal], animal_type))

}





我对该方法的控制器操作是



 [HttpGet] 
public ActionResult create ()
{
var animal = 来自 x in db.Animals
选择 x.animal_type;
ViewData [ Animal] = animal;
return 查看();
}







从下拉列表中选择一个值后,它应显示特定的部分在同一视图上查看。任何想法

解决方案

你需要在你的View中编写类似的代码:

 @using(Html.BeginForm ())
{

@Html.DropDownList(动物类型,
新的SelectList((System.Collections.IEnumerable)ViewData [Animal],animal_type ))
}

< div id =animalForm>
< / div>

< script>


(#Animal_Type)。click(function(){

var selectedAminal =

(#Animal_Type)。val();
alert(selectedAminal);


I have a drop down with certain values

@using (Html.BeginForm())
{

@Html.DropDownList("Animal Type",
    new SelectList((System.Collections.IEnumerable) ViewData["Animal"], "animal_type"))

}



my controller action for that method is

[HttpGet]
        public ActionResult create()
        {
            var animal = from x in db.Animals
                         select x.animal_type;
            ViewData["Animal"] = animal;
            return View();
        }




After selecting a value from the drop down it should display the specific partial view on the same view. Any ideas

解决方案

You need to write code in your View something like:

@using (Html.BeginForm())
{
 
    @Html.DropDownList("Animal Type",
    new SelectList((System.Collections.IEnumerable)ViewData["Animal"], "animal_type")) 
}

<div id="animalForm">
</div>

<script>


("#Animal_Type").click(function () { var selectedAminal =


("#Animal_Type").val(); alert(selectedAminal);


这篇关于在下拉单击时渲染部分视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆