【发布时间】:2026-01-16 00:45:01
【问题描述】:
您已经创建了一个链接,该链接执行对控制器的 ajax 调用,以更新 ID 为 UpdateCart 的跨度。问题是,如果用户未经过身份验证,他会被发送到登录页面,并且会在页面:
从图片中可以看出,我的整个标题标签是如何被复制并添加到跨度标签内的。这是我的代码:
@Ajax.ActionLink("Add To Cart" ,
"AddToCart" ,
"Products",
new {
ProductId = @products.ElementAt(0).Value
},
new AjaxOptions{
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "UpdateCart",
HttpMethod = "GET"
})
public ActionResult AddToCart(string ProductId)
{
if( User.Identity.IsAuthenticated ) {
string username = User.Identity.Name;
CartHelperClass.AddToCart(ProductId , username);
ViewBag.ItemsInCart = CartHelperClass.CountItemsInCart(username);
return PartialView("_AddToCart");
} else {
return RedirectToAction("LogIn" , "Account" , new {
returnUrl = "Products"
});
}
}
如何停止创建重复的标头?
【问题讨论】:
标签: asp.net asp.net-mvc asp.net-mvc-3