asp.net-mvc - 在不提交值的情况下将值从 Kendo DDL 传递到 ActionLink/ActionImage

标签 asp.net-mvc razor kendo-ui actionlink

VS'12 KendoUI InternetApplication 模板 C# asp.net EF 代码优先

我有 2 个下拉列表页面,其中 1 个页面使用 DropDownList 将值发布到 ModelView,另一个只是按 ID 返回。

问题

基本上我想在 View 中保留一个用户可以从中选择的 DDL。此 DDL 的左侧有一个 Actionlink,它应该能够使用所选参数转到新的 ACtion。但我的模型值始终为空。如何传递这个值?

下拉列表

                <label for="Prospects">Prospect:</label>
                @(Html.Kendo().DropDownListFor(m=>m.Prospects)
                      //.Name("clients")
                      .HtmlAttributes(new { style = "width:300px"}) //, id = "clients"})
                      .OptionLabel("Select Prospect...")
                      .DataTextField("ProspectName")
                      .DataValueField("ProspectID")
                      .DataSource(source => {
                           source.Read(read => {
                               read.Action("GetCascadeProspects", "AddCCCTRST");
                           });
                      })
                  )

Action 链接

@Html.ActionImage("ADD", "Prospect", new { id=Model.Prospects.FirstOrDefault() } , "~/Images/Navigation/Add.PNG", "Add")

..., new { id=Model.Prospects.FirstOrDefault() } ,...,...) 
// the Model is null here, how can i pass my value to this actionlink / actionimage?

(ActionImage来自This Post)如果代码需要贴在这里请指教。 (自定义 ActionImage 正在工作,我只是无法传递值....)

UPDATES Model

public class ViewModelCCTRST
{
    public string Clients { get; set; }
    public IEnumerable<dbClient> AvailableClients { get; set; }
    public string Prospects { get; set; }
    public IEnumerable<dbProspect> AvailableProspects { get; set; }
    public string Countys { get; set; }
    public IEnumerable<dbCounty> AvailableCounties { get; set; }
    public string TownShips { get; set; }
    public IEnumerable<dbTownShip> AvailableTownShip { get; set; }
    public string Ranges { get; set; }
    public IEnumerable<dbRange> AvailableRanges { get; set; }
    public string Sections { get; set; }
    public IEnumerable<dbSection> AvailableSection { get; set; }
    public string Tracts { get; set; }
    public IEnumerable<dbTract> AvailableTracts { get; set; }
}

Controller *A JsonResult GET Method and Post Request

    public JsonResult GetCascadeTracts(int sections)
    {
        var tract = db.Tracts.AsQueryable();

        if (0 != sections)
        {
            tract = tract.Where(o => o.SectionID == sections);
        }

        return Json(tract.Select(o => new { TractID = o.TractID, TractName = o.TractNumber }),    JsonRequestBehavior.AllowGet);
    }

    [HttpPost]
    public ActionResult Index(ViewModelCCTRST model)
    {

        if (ModelState.IsValid)
        {

            //string clt = model.Clients;
            string pro = model.Prospects;
            string cnt = model.Countys;
            string twn = model.TownShips;
            string rng = model.Ranges;
            string sct = model.Sections;
            string trt = model.Tracts;

            return Content(cnt + twn + rng + sct + trt);
        }
        else
        {
            return Content("");
        }
    }

**如下所述,我的 Post 方法中确实有值,但我的 View 中没有任何值(这是我希望能够具有使用我的 Actionlinks 的值 w/o 刷新页面)同样,如果我将 Model.(w/e the data is) 绑定(bind)到 action链接 他们给了我一个null reference

最佳答案

您可以为此使用kendo 模板引用:Kendo DropDownList / Customizing templates

@(Html.Kendo().DropDownList()
      .Name("customers")
      .HtmlAttributes(new { style = "width: 400px" })
      .DataTextField("ContactName")
      .DataValueField("CustomerID")
      .DataSource(source =>
      {
          source.Read(read =>
          {
              read.Action("GetCustomers", "Home");
          });
      })
      .Height(300)
      .Template("<img src=\"" + Url.Content("~/Content/web/Customers/") +  "${data.CustomerID}.jpg\" alt=\"${data.CustomerID}\" />" +
                        "<dl>" +
                            "<dt>Contact:</dt><dd>${ data.ContactName }</dd>" +
                            "<dt>Company:</dt><dd>${ data.CompanyName }</dd>" +
                        "</dl>")
)

更新

您得到的是空值,因为您还没有将 Name 分配给您的 kendo 控件。如果不这样做,控件值将不会绑定(bind)到您的模型。

@(Html.Kendo().DropDownListFor(m=>m.Prospects)
                  .Name("Prospects")         // assign appropriate name
                  .HtmlAttributes(new { style = "width:300px"}) //, id = "clients"})
                  .OptionLabel("Select Prospect...")
                  .DataTextField("ProspectName")
                  .DataValueField("ProspectID")
                  .DataSource(source => {
                       source.Read(read => {
                           read.Action("GetCascadeProspects", "AddCCCTRST");
                       });
                  })
              )

关于asp.net-mvc - 在不提交值的情况下将值从 Kendo DDL 传递到 ActionLink/ActionImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18495703/

相关文章:

c# - 在 Html Helper 中创建带有分隔符的选择列表

HTML.TextAreaFor - 删除仅供显示的 html 标签

c# - ASP.NET : Error - Server Error in '/' Application

asp.net - 如何在MVC Razor中处理空子实体

asp.net-mvc - MVC3 一个 View 中的两个局部 View

kendo-ui - 如何自定义Kendo UI Grid行的所选背景颜色

html - Angular Kendo - 在 CSS 或 SCSS 中设置网格列宽

c# - 从 ASP.NET WebForms 迁移到 MVC

c# - ASP.NET MVC3 绑定(bind)到子类

javascript - 上传图片后隐藏kendo ui upload的消息