Jquery 在使用div.load 404'的MVC项目中使用ASPX页面;D
不幸的是,由于遗留软件的原因,我需要在MVC项目中呈现Aspx页面。我想我需要使用JQuery的load方法来实现这一点,然后将aspx页面加载到一个div中。我有一个MVC3项目。这个项目包含一个带有索引方法的HomeController,当然还有一个索引视图 家庭控制器:Jquery 在使用div.load 404'的MVC项目中使用ASPX页面;D,jquery,asp.net,asp.net-mvc,Jquery,Asp.net,Asp.net Mvc,不幸的是,由于遗留软件的原因,我需要在MVC项目中呈现Aspx页面。我想我需要使用JQuery的load方法来实现这一点,然后将aspx页面加载到一个div中。我有一个MVC3项目。这个项目包含一个带有索引方法的HomeController,当然还有一个索引视图 家庭控制器: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; nam
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace CombiningMVCAndAspx.Controllers
{
public class HomeController : Controller
{
//
// GET: /Home/
public ActionResult Index()
{
return View();
}
}
}
其中返回索引视图:
<script type="text/javascript">
$(document).ready(function () {
alert('loading dashboard...');
$('#dashboard').load('~/WebForms/WebForm1.aspx', function (response, status, xhr) {
if (status == "error") {
var msg = "Sorry but there was an error: ";
$("#error").html(msg + xhr.status + " " + xhr.statusText);
}
});
});
</script>
@{
ViewBag.Title = "Index";
}
<h2>
Index</h2>
<div id="dashboard">
</div>
<div id="error">
</div>
$(文档).ready(函数(){
警报(“正在加载仪表板…”);
$(“#仪表板”).load(“~/WebForms/WebForm1.aspx”,函数(响应、状态、xhr){
如果(状态=“错误”){
var msg=“抱歉,出现错误:”;
$(“#error”).html(msg+xhr.status+“”+xhr.statusText);
}
});
});
@{
ViewBag.Title=“Index”;
}
指数
WebForm1.aspx是我想在dashboard div中加载的页面。不幸的是,我得到了错误404 Not Found。这并不奇怪,因为MVC中的路由工作方式当然不同。但我的谷歌fu让我失望,我对MVC不够精通,无法独自解决这个问题。谁能帮我一下吗?提前感谢您与我一起思考。我目前能给您的建议是检查您的
WebForm1.aspx
页面位于何处,并将正确的路径放入Method中。好吧,您实际上了解了一些事情,因为“../../WebForms/WebForm1.aspx”起作用。你知道为什么吗?希望对你有帮助