C# 尝试加载部分内容时,网页返回未定义
我的片面观点有什么错?当我单击学生行时,我从网页收到一个“未定义”错误。我尝试了“result”和“result.responseText”,但它仍然警告“undefined”,不确定控制器操作返回错误而不是成功的原因 以下是我的标题:C# 尝试加载部分内容时,网页返回未定义,c#,entity-framework,jquery,asp.net-mvc-partialview,C#,Entity Framework,Jquery,Asp.net Mvc Partialview,我的片面观点有什么错?当我单击学生行时,我从网页收到一个“未定义”错误。我尝试了“result”和“result.responseText”,但它仍然警告“undefined”,不确定控制器操作返回错误而不是成功的原因 以下是我的标题: Request URL:http://localhost:54933/Base/ShowSpecificStudent Request Method:POST Status Code:200 OK Request Headersview source Accep
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>
我找到了,我在JS函数中的数据类型是“json”,应该是“html”我找到了,我在JS函数中的数据类型是“json”,应该是“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);
}