Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.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
C# 使用dropdownlist中的选定对象更新textboxfor字段中的数据_C#_Asp.net Mvc - Fatal编程技术网

C# 使用dropdownlist中的选定对象更新textboxfor字段中的数据

C# 使用dropdownlist中的选定对象更新textboxfor字段中的数据,c#,asp.net-mvc,C#,Asp.net Mvc,在我的用户可以创建新项目的视图中,他必须从下拉列表中选择一个项目,如下所示: @Html.DropDownListFor(model => model.m_CustomerId, ViewBag.ListCustomers as SelectList, "--- Select Customer ---", new {@class = "CustomerInfo" }) 进行选择时,当前视图中有一些字段的名称将随所做的选择而更新。这些字段如下所示: Item Name: @Html.Te

在我的用户可以创建新项目的视图中,他必须从下拉列表中选择一个项目,如下所示:

@Html.DropDownListFor(model => model.m_CustomerId, ViewBag.ListCustomers as SelectList, "--- Select Customer ---", new  {@class = "CustomerInfo" })
进行选择时,当前视图中有一些字段的名称将随所做的选择而更新。这些字段如下所示:

Item Name: @Html.TextBoxFor(model => model.m_ItemName, new { @disabled = "disabled" }) @Html.ValidationMessageFor(model => model.m_ItemName)<br/>
        Item Date: <span style="font-weight: bold">@Html.DisplayFor(model => model.m_ItemDate)</span> @Html.ValidationMessageFor(model => model.m_ItemDate)<br/>
项目名称:@Html.TextBoxFor(model=>model.m_ItemName,new{@disabled=“disabled”})@Html.ValidationMessageFor(model=>model.m_ItemName)
项目日期:@Html.DisplayFor(model=>model.m_ItemDate)@Html.ValidationMessageFor(model=>model.m_ItemDate)

我读过一些东西,比如可能使用JQuery或Java,但老实说,我不懂这些语言。我怎么能这样做?我不介意尝试语言、脚本或其他任何东西,但我是MVC应用程序的新手,这让我感到困惑。非常感谢

因此,您可能需要通过NuGet Package Manager下载并安装jQuery。一旦你安装了它,我们就可以扩展控制了。您可以通过添加一些属性来扩展
DropDownListFor

@Html.DropDownListFor(model => model.m_CustomerId,
    ViewBag.ListCustomers as SelectList,
    "--- Select Customer ---",
    new
    {
        @class = "CustomerInfo",
        onchange = "function() { $('m_ItemName').val($(this).text()); }"
    }
)

注意,我不介意尝试或使用任何可能是jQuery或javascript的语言,而不是java。哦,你真的需要学习javascript。如果你在做网页开发,这是很重要的。这是一个不错的资源,可以让你继续前进。哈哈,谢谢你的教程@四十二,你说得对。我会很快洗劫这个网站!请记住,模型是您的服务器端对象,下拉列表中的选择发生在前端。模型值在页面加载时呈现。如果您需要执行比显示所选下拉列表值(如Model.CustomerName和Model.CustomerPhone)更复杂的操作,则需要创建javascript对象以保存完整的客户列表,或者进行另一个服务器调用以根据所选值加载客户属性。哦。我懂了。所以这比我想要的更复杂@我不介意试一试。理论上,dropdownlistfor保存着这些值。我想知道用局部视图是否更容易理解?