Asp.net mvc 来自网格的自定义命令按钮isn';t更新局部视图

Asp.net mvc 来自网格的自定义命令按钮isn';t更新局部视图,asp.net-mvc,razor,grid,kendo-ui,partial-views,Asp.net Mvc,Razor,Grid,Kendo Ui,Partial Views,我创建了一个示例项目来说明我的问题 Index.cshtml: @model KendoUIMvcApplication3.Models.Detail @{ ViewBag.Title = "ViewDetails"; Layout = null; } @Html.DisplayFor(m => m.Price) @Html.DisplayFor(m => m.Origin) @使用Kendo.Mvc.UI @模型IEnumerable @{ ViewBag.Ti

我创建了一个示例项目来说明我的问题

Index.cshtml:

@model KendoUIMvcApplication3.Models.Detail
@{
    ViewBag.Title = "ViewDetails";
    Layout = null;
}

@Html.DisplayFor(m => m.Price)
@Html.DisplayFor(m => m.Origin)
@使用Kendo.Mvc.UI
@模型IEnumerable
@{
ViewBag.Title=“主页”;
}
功能点击查看(e){
e、 预防默认值();
var dataItem=this.dataItem($(e.currentTarget).closest(“tr”);
$.ajax({
url:“/Home/ViewDetails”,
数据:{productId:dataItem.Id}
});
}
@(Html.Kendo().Grid(模型)
.姓名(“RoleGrid”)
.列(列=>
{
columns.Bound(p=>p.Id);
columns.Bound(p=>p.Name).Width(“30%”);
columns.Bound(p=>p.Description);
columns.Command(Command=>
{
command.Edit();
command.Destroy();
命令。自定义(“查看”)。单击(“单击查看”);
}).宽度(250);
})
.ToolBar(ToolBar=>ToolBar.Create().Text(“添加”))
.Sortable()
.Scrollable()
.HtmlAttributes(新的{style=“height:350px”})
@{Html.RenderAction(“视图详细信息”,“主页”,新的{productId=0});}
查看my HomeController中的详细信息操作:

@model KendoUIMvcApplication3.Models.Detail
@{
    ViewBag.Title = "ViewDetails";
    Layout = null;
}

@Html.DisplayFor(m => m.Price)
@Html.DisplayFor(m => m.Origin)
public ActionResult视图详细信息(int-productId)
{
细节模型;
if(productId==0)
{
模型=新细节
{
Price=“零”,
原点=“零”
};
}否则{
模型=新细节
{
Price=productId.ToString(),
Origin=productId.ToString()
};
}
返回视图(模型);
}
ViewDetails.cshtml:

@model KendoUIMvcApplication3.Models.Detail
@{
    ViewBag.Title = "ViewDetails";
    Layout = null;
}

@Html.DisplayFor(m => m.Price)
@Html.DisplayFor(m => m.Origin)
一切正常

单击自定义“查看”按钮将触发javascript,这将对my
ViewDetails
操作进行ajax调用。正确传递了
productId
值,但是my
ViewDetails
操作的
返回(模型)
根本不会更新我的查看页面


我是否应该在index.cshtml中使用
RenderAction

在单击任何按钮时,在网格下显示该部分视图,您应该使用$.ajax的success回调函数

@using Kendo.Mvc.UI
@model IEnumerable<KendoUIMvcApplication3.Models.Product>
@{
    ViewBag.Title = "Home Page";
}
<script type="text/javascript">
    function clickView(e) {
        e.preventDefault();
        var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
        $.ajax({
            url: "/Home/ViewDetails",
            data: { productId: dataItem.Id },
            success:function(response){
                $('#viewDetails').html(response);
            }
        });
    }
</script>
<div>
    @(Html.Kendo().Grid(Model)
          .Name("RoleGrid")
          .Columns(columns =>
              {
                  columns.Bound(p => p.Id);
                  columns.Bound(p => p.Name).Width("30%");
                  columns.Bound(p => p.Description);
                  columns.Command(command =>
                      {
                          command.Edit();
                          command.Destroy();
                          command.Custom("View").Click("clickView");
                      }).Width(250);
              })
          .ToolBar(toolbar => toolbar.Create().Text("Add"))
          .Sortable()
          .Scrollable()
          .HtmlAttributes(new { style = "height: 350px" })
</div>

<div id="viewDetails"></div>
@使用Kendo.Mvc.UI
@模型IEnumerable
@{
ViewBag.Title=“主页”;
}
功能点击查看(e){
e、 预防默认值();
var dataItem=this.dataItem($(e.currentTarget).closest(“tr”);
$.ajax({
url:“/Home/ViewDetails”,
数据:{productId:dataItem.Id},
成功:功能(响应){
$('#viewDetails').html(回复);
}
});
}
@(Html.Kendo().Grid(模型)
.姓名(“RoleGrid”)
.列(列=>
{
columns.Bound(p=>p.Id);
columns.Bound(p=>p.Name).Width(“30%”);
columns.Bound(p=>p.Description);
columns.Command(Command=>
{
command.Edit();
command.Destroy();
命令。自定义(“查看”)。单击(“单击查看”);
}).宽度(250);
})
.ToolBar(ToolBar=>ToolBar.Create().Text(“添加”))
.Sortable()
.Scrollable()
.HtmlAttributes(新的{style=“height:350px”})