如何使用Chosen jquery插件在MVC 3中发布所选值。我不知道如何发布我选择的值。这是我的代码到目前为止的样子..
这是我的帖子表单,其中包含选择列表和发布到我的控制器的提交按钮。
@using (Html.BeginForm("Search", "Home", FormMethod.Post))
{
<select data-placeholder="Choose a Category..." class="chzn-select" multiple style="width: 650px;" tabindex="4">
<option value=""></option>
@foreach (var item in Model.Categories)
{
<option value="@item.Id">@item.Name</option>
}
</select><br/>
<button type="submit" value="Search" name="button">Search</button>
}
这是我正在使用的模型。
public class CategoryModel
{
public List<Category> Categories { get; set; }
public CategoryModel()
{
Categories = new List<Category>();
Category cat = new Category();
cat.Id = 1;
cat.Name = "Ekonomi";
Categories.Add(cat);
cat = new Category();
cat.Id = 2;
cat.Name = "IT";
Categories.Add(cat);
cat = new Category();
cat.Id = 3;
cat.Name = "Teknik";
Categories.Add(cat);
}
}
public class Category
{
public int Id { get; set; }
public string Name { get; set; }
}
那么如何从文本框中检索值?
答案 0 :(得分:0)
我相信评论会作为参数添加到函数中,因此,在控制器中:
Function Index(Optional sortOrder As String = "", Optional searchString As String = "", Optional page As Integer = 1) As ViewResult
在视图中:
@Using Html.BeginForm()
@<p>
Find by name: @Html.TextBox("SearchString", ViewBag.CurrentFilter)
<input type="submit" value="Search" />
</p>
End Using
您也可以通过网址发送参数:
@Html.ActionLink("Name", "Index", New With {.sortOrder = ViewBag.NameSortParam})
注意:这是VB。
答案 1 :(得分:0)
在视图中:
@Html.DropDownList("naicsCodeSelect", ViewBag.selectNAICS as List<SelectListItem>, new { @multiple = "true", @class = "form-control col-md-7 col-xs-12 chosen-select" })
在控制器中:
[HttpPost]
public ActionResult Edit(Industry model, int[] naicsCodeSelect)
{
if (!ModelState.IsValid)
{}