0

如何将 Kendo ui 下拉列表与模型绑定以及如何使用按钮将选定的值发送到控制器单击以进行其他操作....

你能详细解释一下吗……我是个新鲜人……提前谢谢

4

2 回答 2

0

看法:

@model Contract
@{
    var vendors = ViewData["Lookups"] as List<Vendor>;
}
@using (Html.BeginForm("Create", "Contract", FormMethod.Post, new { id = "contractDetailsForm" }))
{
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>Contract</legend>
        <div>
            @{
            Html.Kendo().DropDownListFor(model => model.VendorId).Name("VendorId")
                .BindTo(new SelectList(vendors, "ID", "DisplayName", "Nothing Selected"))
                .HtmlAttributes(new { @style = "width:250px;" })
                .Value(Model.VendorId.ToString())
                .Render();
            }
        </div>
        <div>
            <button type="submit" class="k-button k-button-icontext">
                <span class="k-icon k-insert"></span>Create Contract</button>
        </div>
    </fieldset>
}

控制器:

[HttpPost]
public ActionResult Create(Contract contract)
{
    if (ModelState.IsValid)
    {
        contract.ID = Guid.NewGuid();
        _repository.Add(contract);
        _repository.SaveChanges();
        //return or redirect to another View ...
    }
    return View("Create", contract);
}
于 2013-09-23T19:10:21.123 回答
0

为下拉列表编写选择事件,例如

function onSelect(e) {                                                     
       var DropDownval = $("#QuestionType").val();
}

将此值放入会话或变量中并将其传递给控制器​​。

于 2013-09-24T04:05:06.877 回答