提交按钮,MVC3,VB

时间:2012-04-02 22:55:06

标签: vb.net asp.net-mvc-3 http-post

我无法使用从下拉列表中选择的值。您如何推荐从视图中传递选定的值?

理想情况下,我们希望使用选定的下拉值来确定查询。任何帮助表示赞赏!

由于

1 个答案:

答案 0 :(得分:0)

我会将它们包含在视图模型中,然后将viewmodel传递回控制器。

视图模型

public class vm
{
 //your other viewmodel data

 public string? SelectedValue { get; set; }
 public SelectList forDropDownUse { get; set; }
}

视图

@model namespace.vm
@using (Html.BeginForm())
{
 @Html.DropDownListFor(m => m.SelectedValue, forDropDownUse, " -- Select A Value -- ")
 <input type="Submit" value="submit model" />
}

然后在您的帖子操作中,只需从发布的模型对象中获取所选值

控制器(抱歉,这是在c#中)

[HttpPost]
public ActionResult postedAction(vm model)
{
 //actions with other data in model
 string selectedValue = model.SelectedValue.Value;
 //work with selected value
 return RedirectToAction("SomeDisplayAction");
}

http://www.developerfusion.com/tools/convert/csharp-to-vb/

转换为vb.net
<HttpPost> _
Public Function postedAction(model As vm) As ActionResult
 'actions with other data in model
 Dim selectedValue As String = model.SelectedValue.Value
 'work with selected value
 Return RedirectToAction("SomeDisplayAction")
End Function