我试图渲染不同的部分视图取决于侧边栏的点击,当我点击侧边栏中的1个元素时,它调用jquery,它有一个应该重定向到控制器的url.action,特定的控制器应该返回一个视图,事情是它找不到控制器,我在accountcontroller中有动作,它的名字叫_InformacaoBasica
这就是我做的
使用侧边栏链接查看
<div class="row" style="margin-top:15px">
<div class="col-md-2" style="border-right:1px solid gray;">
<div class="row caixaUser" id="linkInfo" style="margin-top:25px;padding:5px;">
<a href="#" class="linkUser"><span class="glyphicon glyphicon-user black"></span> Informação básica</a>
</div>
<div class="row caixaUser" style="margin-top:25px;padding:5px;">
<a href="#" class="linkUser" id="linkOutra"><span class="glyphicon glyphicon-folder-open black"></span> Outras Informações</a>
</div>
<div class="row caixaUser" style="margin-top:25px;padding:5px;">
<a href="#" class="linkUser" id="linkSegu"><span class="glyphicon glyphicon-lock black"></span> Segurança</a>
</div>
<div class="row caixaUser" style="margin-top:25px;padding:5px;">
<a href="#" class="linkUser" id="linkTag"><span class="glyphicon glyphicon-tags black"></span> Tags</a>
</div>
<br /><br />
</div>
我的Jquery
$('#linkInfo').click(function () {
$('.vistaParcial').load('@Url.Action("_InformacaoBasica", "Account")')
});
我的控制器
public ActionResult _InformacaoBasica()
{
var id = User.Identity.GetUserId();
ApplicationUser user = db.Users.Include(u => u.Tags).FirstOrDefault(u => u.Id.Equals(id));
preencherTagUtilizador(user);
var role = (from s in db.Roles where s.Id == user.TipoUtilizador select s.Name).First();
EditarUtilizadorViewModel model = new EditarUtilizadorViewModel();
model.Utilizador = user.Nome;
model.Email = user.Email;
return PartialView("~/Views/PartialViews/_InformacaoBasica",model);
}
答案 0 :(得分:0)
您不能在外部JS文件中包含razor指令(例如@Url.Action
)。您必须在视图中的内联代码中执行此操作,或者您必须自己编制URL并包含此内容:
$('#linkInfo').click(function () {
$('.vistaParcial').load('/Account/_InformacaoBasica')
});
如果您的网站未在域根目录中托管,那么您也必须对此进行说明。