Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/9.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
Asp.net mvc 如何在.NETMVC中从DropDownList获取文本?_Asp.net Mvc_Html Select - Fatal编程技术网

Asp.net mvc 如何在.NETMVC中从DropDownList获取文本?

Asp.net mvc 如何在.NETMVC中从DropDownList获取文本?,asp.net-mvc,html-select,Asp.net Mvc,Html Select,好的,我使用了这样一个文本框: @Html.TextBoxFor(u=>u.Time) 现在我想用下拉列表替换文本框,我这样做了: @Html.DropDownList("FromDD",new SelectList (new[] {"first","second","third"})) 如何从下拉列表中获取文本并将其保存在模型(model.Time)中?您可以在操作方法中将其作为参数传递 [HttpPost] public ActionResult ActionName(string

好的,我使用了这样一个文本框:

@Html.TextBoxFor(u=>u.Time)
现在我想用下拉列表替换文本框,我这样做了:

@Html.DropDownList("FromDD",new SelectList (new[] {"first","second","third"}))

如何从下拉列表中获取文本并将其保存在模型(model.Time)中?

您可以在操作方法中将其作为参数传递

[HttpPost]
public ActionResult ActionName(string FromDD){

}
表单必须将action属性设置为ActionName:

<form action="ActionName">
...
@Html.DropDownList("FromDD",new SelectList (new[] {"first","second","third"}))

...
@DropDownList(“FromDD”,new SelectList(new[]{“first”,“second”,“third”}))

您可以在操作方法中将其作为参数传递

[HttpPost]
public ActionResult ActionName(string FromDD){

}
表单必须将action属性设置为ActionName:

<form action="ActionName">
...
@Html.DropDownList("FromDD",new SelectList (new[] {"first","second","third"}))

...
@DropDownList(“FromDD”,new SelectList(new[]{“first”,“second”,“third”}))
您可以使用

@DropDownListFor(u=>u.Time,new SelectList(new[]{“first”、“second”、“third”}))

你可以用

@DropDownListFor(u=>u.Time,new SelectList(new[]{“first”、“second”、“third”}))


根据您的示例,您要查找的值将作为名为fromd的字符串发布。用作第一个参数的字符串将是数据绑定器要将值绑定到的属性的名称。
如果需要,可以使用强类型重载

@Html.DropDownListFor(p => p.Time, new SelectList (new[] {"first","second","third"}))

这将以名为Time的字符串形式发回数据,与您的文本框完全相同

根据您的示例,您要查找的值将作为名为fromd的字符串发布。用作第一个参数的字符串将是数据绑定器要将值绑定到的属性的名称。
@Html.HiddenFor(m=>m.Time new{@id='hdnTime'})
如果需要,可以使用强类型重载

@Html.DropDownListFor(p => p.Time, new SelectList (new[] {"first","second","third"}))
这将以名为Time的字符串形式发回数据,与您的文本框完全相同

@Html.HiddenFor(m=>m.Time new{@id='hdnTime'})
在提交之前,在客户端的下拉列表中设置此选项

$('#hdnTime').val($('#fromDD option:selected').text())
在提交之前,在客户端的下拉列表中设置此选项

$('#hdnTime').val($('#fromDD option:selected').text())

对不起,那不是故意的我只是发现你是对的对不起,那不是故意的我只是发现你是对的