2013-09-10 56 views
1

我的部分視圖有什麼問題?點擊學生行時,我收到來自網頁的「未定義」錯誤。我想「結果」和「result.responseText」,但它仍然提醒「未定義」不知道爲什麼控制器動作返回錯誤而不是成功當試圖加載部分時,網頁返回undefined

這裏有我的頭:

Request URL:http://localhost:54933/Base/ShowSpecificStudent 
Request Method:POST 
Status Code:200 OK 
Request Headersview source 
Accept:application/json, text/javascript, */* 
Accept-Encoding:gzip,deflate,sdch 
Accept-Language:en-US,en;q=0.8 
Connection:keep-alive 
Content-Length:4 
Content-Type:application/x-www-form-urlencoded 
Host:localhost:54933 
Origin:http://localhost:54933 
Referer:http://localhost:54933/base/ShowStudents 
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.57 Safari/537.36 
X-Requested-With:XMLHttpRequest 
Form Dataview sourceview URL encoded 
id:7 
Response Headersview source 
Cache-Control:private 
Connection:Close 
Content-Length:310 
Content-Type:text/html; charset=utf-8 
Date:Tue, 10 Sep 2013 21:24:24 GMT 
Server:ASP.NET Development Server/10.0.0.0 
X-AspNet-Version:4.0.30319 
X-AspNetMvc-Version:2.0 

的Javascript:

$(function() { 
$("tr[name='StudentTableRow']").click(showStudent);  
}); 

function showStudent() {  
var link = '/Base/ShowSpecificStudent'; 
var id = this.cells[0].innerText; 

$.ajax({ 
    type: 'POST', 
    url: link, 
    data: { id: id }, 
    dataType: 'json', 
    success: function (result) { 
     $("#StudentDetail").html(result.responseText); 
     //$("#StudentDetail").html(result); 
    }, 
    error: function (result) { 
     alert(result.message); 
    } 
}); 

主視圖:

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<IEnumerable<Student.Models.Student>>" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml" > 
<head runat="server"> 
    <script type="text/javascript" src="/Scripts/jquery-1.4.1.min.js"></script> 
    <script type="text/javascript" src="/Scripts/app/BaseScript.js"></script> 
    <link rel="stylesheet" type="text/css" href="/Content/Site.css" /> 

</head> 
<body> 
    <table> 
     <tr> 
      <th > 
       ID 
      </th>   
     </tr> 

     <%if(Model != null) %> 
    <% foreach (var item in Model) { %> 

     <tr name="StudentTableRow"> 
      <td> 
       <%: item.StudentID%> 
      </td>    
     </tr> 

    <% } %> 

    </table> 

    <% using (Html.BeginForm()) %> 
     <% { %> 
     <div id ="StudentDetail"> 
    <% Html.RenderPartial("ShowSpecificStudent", new List<Student.Models.Student>()); %> 
    </div>  
     <% } %> 

</body> 
</html> 

管窺:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %> 

<div> 
<table> 
     <tr> 
      <th> 
       Student Description 
      </th>    
     </tr> 
</table> 
<table> 
     <% if (Model != null) %>     
     <% foreach (var item in Model) { %> 
     <tr> 
      <td > 
       <%: item.StudentDescription%> 
      </td>  
     </tr> 
    <%}%> 
</table> 
</div> 

控制器動作:

 [HttpPost()] 
     public ActionResult ShowSpecificStudent(string id) 
     { 
      StudentEntities context = new StudentEntities(); 
      Int16 studentId = Convert.ToInt16(student); 

      ViewData.Model = context.Students.Where(i => i.StudentID == studentId); 
      return PartialView("~/Views/Shared/ShowSpecificStudent.ascx", ViewData.Model); 
     } 

回答

0

我發現,在JS功能我的數據類型是 'JSON',這應該是 'HTML'

相關問題