实现Ajax问题MVC3返回HTML.Partial页 [英] Problems implementing Ajax to return a HTML.Partial page in MVC3

查看:116
本文介绍了实现Ajax问题MVC3返回HTML.Partial页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现一个Ajax方式来更新我的数据网格。到目前为止,我有codeD在我的控制器以下内容:

I am trying to implement an Ajax way to update my data grid. So far I have coded the following in my controller:

public ActionResult Detail(string ac, string me) {     
   vm.AdminDetails = _link.Detail(ac + me).ToList();      
   if (Request.IsAjaxRequest())         
      return PartialView(vm);     
   return View(vm); 
} 

我的观点的快照看起来是这样的:

My snapshot of the view looks like this:

@model ViewModels.Shared.BaseViewModel
@{ 
    Layout = "~/Areas/Administration/Views/Menus/_Layout.cshtml";
}

@section content {
<div class="bdy_box">
        <div id="detailData" class="rep_tb0">
        // code to generate the list of data
        </div>
</div>

我的JavaScript的快照看起来是这样的:

My snapshot of the javascript looks like this:

function reload(entity, pk) {
    $.ajax({
        url: "/Administration/" + entity + "s/Detail",
        data: { pk: pk },
        dataType: 'html',
        cache: false,
        success: function (responseText) {
            $('#detailData').html(responseText);
        }
    });
};

中的数据被打回来,但我的问题是,其他数据也将被返回。当我看detailData的内容的div我看到比我需要更多。比如我看到类似以下内容:

The data does get returned BUT my problem is other data also gets returned. When I look at the contents of the detailData div I see much more than I need. For example I see something like the following:

<div class="rep_tb0" id="detailData">  
<title></title>    
<meta content="" name="title">    
<meta content="" name="description">     
<meta content="" name="keywords">    
<link type="image/x-icon" href="/Content/Favicons/default.ico" rel="shortcut icon">     
<link type="text/css" rel="stylesheet" href="/Content/Stylesheets/Style203.css">

是否有一个原因,它显示了我这一切和我如何能阻止它显示的所有信息这个头型?

Is there a reason why it's showing me all this and how can I stop it showing all this header type of information?

推荐答案

梅丽莎,

我假设你已经称为partialview _detail.cshtml (如果没有,你需要创建一个)??

I'm assuming that you have a partialview called _detail.cshtml (if not, you need to create one)??

我相信你可能是实际调用根据样品的'全'视图detail.cshtml。我建议你​​打电话给你的行动是大致如下:

I believe that you may be actually invoking the 'full' view detail.cshtml based on your sample. I'd suggest that you call your action it along the following lines:

public ActionResult Detail(string ac, string me) {     
   vm.AdminDetails = _link.Detail(ac + me).ToList();      
   if (Request.IsAjaxRequest())         
      return PartialView("_details", vm);     
   return View(vm); 
} 

这篇关于实现Ajax问题MVC3返回HTML.Partial页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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