1

我的代码如下所示:

@(Html.Kendo().DropDownList()
    .Name("MyDropDownList")
    .BindTo(new string[] { "StringOne", "StringTwo", "StringThree"})
    .Events(e => e.Change("MyDropDownListOnchange")))

在脚本中:

function MyDropDownListOnchange() {
    var val = $("#MyDropDownList").val();
    $("#LoadingDiv").load("Views/StringView/_StringOne.cshtml");

我尝试了几种变体:

  • “~/视图/......
  • “../视图/......
  • “观点/....
  • “图像视图/....

错误:

//localhost:43222/Views/StringView/_StringOne.cshtml 404 (Not Found)

4

2 回答 2

1

试试这种方式

function change() {
    var val = $("#OptionsDrop").val();

    //you will have to make a switch case here depending on how many options you have in the DDL

    $.ajax({
        url: '/StringView/GetStringOne',
        dataType: 'html',
        success: function (data) {
            $('#LoadingDiv').html(data);
        }
    });

这包括控制器

[HttpGet]
public PartialViewResult GetStringOne()
{
    return PartialView("_StringOne");
} 
于 2013-09-11T18:42:41.233 回答
0
$("#LoadingDiv").load("Views/StringView/_StringOne.cshtml");

删除 .cshtml 试试这个:

$("#LoadingDiv").load("Views/StringView/_StringOne");

并确保在您的控制器中您已返回此部分视图

就像是

[httpget]
public PartialViewResult _StringOne()
{
   return PartialView();
}
于 2013-09-11T17:28:54.727 回答