C# 为什么Kendo ComboBoxFor show 0而不是从另一个视图传递的属性绑定模型?

C# 为什么Kendo ComboBoxFor show 0而不是从另一个视图传递的属性绑定模型?,c#,asp.net-mvc,asp.net-mvc-4,kendo-asp.net-mvc,C#,Asp.net Mvc,Asp.net Mvc 4,Kendo Asp.net Mvc,我是ASP MVC新手。 我对剑道有意见。我从Stack中尝试了几十个示例,但都没有成功 我想将两个ID从一个视图传递到另一个视图,并在两个ComboboxFor中使用它们。在这两个视图中,我使用相同的模型。 下面是我的两个目标ID 型号 public class Wymiarowanie_PorownajModel { public int Target1 { get; set; } public int Target2 { get; set; } } 这是我在目标视图中绑定

我是ASP MVC新手。 我对剑道有意见。我从Stack中尝试了几十个示例,但都没有成功

我想将两个ID从一个视图传递到另一个视图,并在两个ComboboxFor中使用它们。在这两个视图中,我使用相同的模型。 下面是我的两个目标ID

型号

public class Wymiarowanie_PorownajModel
{
    public int Target1 { get; set; }
    public int Target2 { get; set; }
}
这是我在目标视图中绑定此ID的两种方法。两者都不起作用。 ComboBox用于显示0,而不是从另一个视图传递的属性绑定模型。将列表绑定到ComboboxFor,以便正确工作

查看

@model WebApp.Models.Wymiarowanie_PorownajModel
<td class="align_center">
            @(Html.Kendo().ComboBoxFor(model => model.Target1)
            .DataTextField("Opis")
            .DataValueField("Id")
            .Suggest(true)
            .Name("Target1")
            .Filter("contains")
            .BindTo((System.Collections.IEnumerable)ViewData["opis"])
            .Placeholder("Wybierz tłoka bazowego...")
            .HtmlAttributes(new { style = "width:225px;" })
            )
        </td>
        <td class="align_center">
            @(Html.Kendo().ComboBoxFor(model => model.Target2)
            .DataTextField("Nazwa").DataValueField("Id")
            .Suggest(true)
            .Filter("contains")
            .Placeholder("Wybierz opcję 1...")
            .HtmlAttributes(new { style = "width:225px;" })
            .DataSource(source =>
            {
                source.Read(read =>
                {
                    read.Action("PodajRysunek", "Wymiarowanie_PorownajWymiaryTlokow");
                })
                                 .ServerFiltering(true);
            })
            )
        </td>
我不知道怎么了。 您是否愿意帮助我找到此错误的解决方案? 我希望我的代码对你是清楚的对不起我的英语


这是一个如何绑定数据的示例

   public ActionResult Products_Read([DataSourceRequest]DataSourceRequest request)
{
    using (var northwind = new NorthwindEntities())
    {
        IQueryable<Product> products = northwind.Products;
        DataSourceResult result = products.ToDataSourceResult(request);
        return Json(result);
    }
}
public ActionResult产品\u读取([DataSourceRequest]DataSourceRequest请求)
{
使用(var northwind=new NorthwindEntities())
{
IQueryable产品=northwind.products;
DataSourceResult=products.ToDataSourceResult(请求);
返回Json(结果);
}
}

更多信息你可以找到一个解释:我犯了菜鸟的错误。我把控制器中的实例搞砸了。我想使用两个单独的视图和两个单独的控制器

我清理了一个简化的代码并将其放在一个控制器上

我有同样的模型课。最后,我的ComboBoxFor如下所示:

@(Html.Kendo().ComboBoxFor(model => model.Target)
    .DataTextField("Nazwa").DataValueField("Id")
    .Suggest(true)
    .Filter("contains")
    .Placeholder("Wybierz opcję 1...")
    .HtmlAttributes(new { style = "width:225px;" })
    .DataSource(source =>
        {
            source.Read(read =>
            {
                read.Action("PodajRysunek", "Wymiarowanie_Porownaj");
            })
                             .ServerFiltering(true);
        })
            )
现在我只使用JsonResultPodajRysunek方法将列表绑定到combobox

我改变了第二个视图的一点方法,它的外观由按钮调用

public ActionResult WymiaryTlokow(Wymiarowanie_PorownajModel wymiarowaniePorownajModel)
    {
        this.wym = wymiarowaniePorownajModel;
        return View(wym);
    }

学习永远不晚。:)

感谢您的回复,但我对普通梳妆盒有问题,而不是网格。幸运的是,您给了我一个解决方案的想法,我将尝试。您在Telerik文档中的示例使我在数据绑定中发现了一个错误。我通过清除代码并使用文档中的示例解决了这个问题。Dziękujęza naprowadzenie.)您的页面上似乎存在javascript错误。尝试将Javascript错误通知程序()添加到Chrome并运行您的页面(或查看控制台日志)以查看是否存在任何错误。@LongLe:Message from JsEN-“此页面上没有错误:(”控制台日志中也没有错误。休息一天后,没有编码,我发现了绑定数据的愚蠢错误。我可能需要在工作中休息一下。不过,感谢您为浏览器提供了出色的附加功能!请提供一个解决方案,详细说明您为解决此问题所做的具体操作,而不是更新您的问题。这是为了帮助未来的访问者理解并避免混淆。谢谢。
public ActionResult WymiaryTlokow(Wymiarowanie_PorownajModel wymiarowaniePorownajModel)
    {
        this.wym = wymiarowaniePorownajModel;
        return View(wym);
    }