Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
基于DropDownList的Asp.Net文本框_Asp.net_Asp.net Mvc - Fatal编程技术网

基于DropDownList的Asp.Net文本框

基于DropDownList的Asp.Net文本框,asp.net,asp.net-mvc,Asp.net,Asp.net Mvc,我有一个下拉列表和3个文本框,如下所示: @(Html.Kendo().DropDownList() .Name("Lager") .DataValueField("LagerId") .DataTextField("LagerIdentifier") .BindTo((System.Collections.IEnumerable)ViewData["Lager"]) ) @Html.TextBoxFor(model => model.Name1, ne

我有一个
下拉列表
和3个
文本框
,如下所示:

@(Html.Kendo().DropDownList()
    .Name("Lager") 
    .DataValueField("LagerId")
    .DataTextField("LagerIdentifier")
    .BindTo((System.Collections.IEnumerable)ViewData["Lager"])
)

@Html.TextBoxFor(model => model.Name1, new { @readonly = "readonly" })
@Html.TextBoxFor(model => model.Name2, new { @readonly = "readonly" })
@Html.TextBoxFor(model => model.Name3, new { @readonly = "readonly" })
public class Lager
{
    public int LagerId { get; set; }
    public string LagerIdentifier { get; set; }
    public string Name1 { get; set; }
    public string Name2 { get; set; }
    public string Name3 { get; set; }
}
基本上,我想实现的是,如果用户从下拉列表中选择某个内容,我想相应地自动更改文本框的值

我的
Lager
型号如下所示:

@(Html.Kendo().DropDownList()
    .Name("Lager") 
    .DataValueField("LagerId")
    .DataTextField("LagerIdentifier")
    .BindTo((System.Collections.IEnumerable)ViewData["Lager"])
)

@Html.TextBoxFor(model => model.Name1, new { @readonly = "readonly" })
@Html.TextBoxFor(model => model.Name2, new { @readonly = "readonly" })
@Html.TextBoxFor(model => model.Name3, new { @readonly = "readonly" })
public class Lager
{
    public int LagerId { get; set; }
    public string LagerIdentifier { get; set; }
    public string Name1 { get; set; }
    public string Name2 { get; set; }
    public string Name3 { get; set; }
}
控制器

public class Names
{
    public string theEnum { get; set; }

    public string Name1 { get; set; }
    public string Name2 { get; set; }
    public string Name3 { get; set; }
}

public enum theEnum
{
    Value1,
    Value2,
    Value3
}

public class PassValue
{
    public string passValue { get; set; }
}

public class HomeController : Controller
{
    [HttpPost]
    public ActionResult Tut112(PassValue passVal)
    {
        return Json(new
        {
            RetVal = passVal.passValue
        }
        , @"application/json");
    }

    public ActionResult Tut112()
    {
        return View();
    }
看法

@{
布局=空;
}
图坦卡蒙
$(函数(){
$(“#ajaxButton”)。单击(函数(){
var SendData={passValue:$(“#passValue”).val()};
$.ajax({
类型:“POST”,
url:“/Home/Tut112”,
数据:SendData,
数据类型:“json”,
成功:功能(数据){
如果(data.RetVal=='Value1'){
$(“#Name1”).val(data.RetVal);
}
else if(data.RetVal==“Value2”){
$(“#Name2”).val(data.RetVal);
}
否则{
$(“#Name3”).val(data.RetVal);
}
}
});
})
})
@型号testy2016 1006.Controllers.Names
@DropDownList(“Envs”、新的选择列表(Enum.GetValues(typeof(Testy20161006.Controllers.theEnum))、“Select Enivronment”、新的{id=“passValue”、@class=“form control”})
@Html.TextBoxFor(model=>model.Name1,新的{@readonly=“readonly”})
@Html.TextBoxFor(model=>model.Name2,新的{@readonly=“readonly”})
@Html.TextBoxFor(model=>model.Name3,新的{@readonly=“readonly”})

您是希望在用户选择内容时将页面发回,还是希望页面更改而不发回?这将决定您是需要AJAX(客户端)代码还是服务器端代码。谢谢您的回复!不,我不想让它发回。ViewData[“Lager”]包含一个包含所有元素的列表。我只是不知道如何用textboxs@AnnL来填充它。应该根据用户在DropDownList中选择的内容来驱动这些值。它们是只读的,忘了提那个@查德