如何剑道UI下拉列表中选择值的ID传递到控制器? [英] how to pass the ID of the kendo Ui dropdown selected value onto the controller?

查看:232
本文介绍了如何剑道UI下拉列表中选择值的ID传递到控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创造一个我使用KENDO UI下拉的应用程序。问题是我想从我的观点到数据库中更新值。在下拉列表中的任意值的选择与之相关的ID应传递到控制器所需的数据库选择更新。但这里的下拉列表中的任何选择的ID通过零作为值到控制器。

I am trying to create an application where i am using KENDO UI Dropdown. The Problem is i want to update the values from my view into the database . On selection of the any value in the dropdown the ID associated with it should be passed onto the controller for the required database updation. But here the ID for any selection of the dropdown list passes "null" as the value onto the controller .

我的看法

@using Kendo.Mvc.UI
@model ExamplekendoDropdown.Models.FacilityGroup

@{
    ViewBag.Title = "FacilityGroup";
}

<h2>FacilityGroup</h2>

@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>FacilityGroup</legend>

        <div id="RegionName"  class="editor-label">
            @Html.LabelFor(model => model.RegionId)
        </div>
        <div class="editor-field">
           @* @Html.EditorFor(model => model.RegionName)*@
           @(Html.Kendo().DropDownList()
          .Name("Region")
          .DataTextField("RegionName")
          .DataValueField("RegionId")
          .DataSource(source =>
          {
              source.Read(read =>
              {
                  read.Action("GetRegion", "Fill");
              });

          })
    )
            @Html.ValidationMessageFor(model => model.RegionId)
        </div>
     <div id="Rest">
@*<form method="post" action='@Url.Action("Submit")' style="width:45%">
    <div>
        @(Html.Kendo().Upload()
            .Name("files")
        )
        <p>
            <input type="submit" value="Submit" class="k-button" />
        </p>
    </div>
</form>*@

        <div class="editor-label">
            @Html.LabelFor(model => model.FaclityGroupName)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.FaclityGroupName)
            @Html.ValidationMessageFor(model => model.FaclityGroupName)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.status)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.status)
            @Html.ValidationMessageFor(model => model.status)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.CreationDate)
        </div>
        <div class="editor-field">
          @*  @Html.EditorFor(model => model.CreationDate)*@
          @(Html.Kendo().DatePicker()
              .Name("datepicker")
              .Value("17/08/2011")
              .HtmlAttributes(new { style = "width:150px" })
        )
            @Html.ValidationMessageFor(model => model.CreationDate)
        </div>

        <p>
            <input type="submit" value="Create" />
        </p>
        </div>

    </fieldset>
}
        <div>
        @Html.ActionLink("See the List", "List")
        </div>
<div>
    @Html.ActionLink("Back to List", "About")
</div>
<script type="text/javascript">
    $(document).ready(function () {

        $("#RegionName").click(function () {
            $("#Rest").show();
        });
    });
</script>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

控制器: -

Controller :-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ExamplekendoDropdown.Models;

namespace ExamplekendoDropdown.Controllers
{
    public class FacilityGroupController : Controller
    {
        //
        // GET: /FacilityGroup/

        public ActionResult FacilityGroup()
        {
            return View();
        }
        [HttpPost]
        public ActionResult FacilityGroup(FacilityGroup objadd)
        {
            AMIEntities1 obj1 = new AMIEntities1();
            Facility objtbl = new Facility();

                objtbl.RegionId = Convert.ToInt16(objadd.RegionId);
                objtbl.FaclityGroupName = objadd.FaclityGroupName.ToString();
                objtbl.Status = objadd.status;
                objtbl.CreationDate = objadd.CreationDate;

                obj1.AddToFacilities(objtbl);
                obj1.SaveChanges();
                obj1.AcceptAllChanges();


            return View();
        }
    }
}

请帮助!

推荐答案

我会建议你使用DropDownListFor(),然后还要确保该.Name点属性的名称相匹配。你的情况:

I would suggest that you use DropDownListFor() and then also make sure that the .Name matches the name of the property. In your case:

 @(Html.Kendo().DropDownListFor(model => model.RegionId)
      .Name("RegionId")
      .DataTextField("RegionName")
      .DataValueField("RegionId")
      .DataSource(source =>
      {
          source.Read(read =>
          {
              read.Action("GetRegion", "Fill");
          });
      })
  )

这篇关于如何剑道UI下拉列表中选择值的ID传递到控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆