Asp.net 将Url重定向到另一个操作方法

Asp.net 将Url重定向到另一个操作方法,asp.net,redirect,asp.net-mvc-5,notifications,url-redirection,Asp.net,Redirect,Asp.net Mvc 5,Notifications,Url Redirection,我正在做通知模块。下面的代码显示了通知表模型 public class Notification { [Key] public int NotificationID { get; set; } . . [Required] public bool Active { get; set; } } 当用户单击通知时,bool Active应设置为false,然后重定向到url列中单独指定的url。我已通过信号器完成通知,但单击通知重定向到url未完成。

我正在做通知模块。下面的代码显示了通知表模型

public class Notification
{
    [Key]
    public int NotificationID { get; set; }
    .
    .
    [Required]
    public bool Active { get; set; }
}

当用户单击通知时,bool Active应设置为false,然后重定向到url列中单独指定的url。我已通过信号器完成通知,但单击通知重定向到url未完成。我无法重定向到指定的url

您可以在action方法中更新your table记录,当用户单击通知项时将执行该操作

public ActionResult NotificationRedirect(int notificationId) 
{ 
   var notification = db.Notifications.FirstOrDefault(notificationId);
   if(notification!=null)
   {
       notification.Active=false;
       db.Entry(notification).State = EntityState.Modified;
       db.SaveChanges();
       return Redirect(notification.Url); 
   } 
   return View("NotificationNotFound"); //make sure you have a view with this name
}
现在,在客户端,当收到singlaR的带有锚定标记的调用时,您需要构建标记,其中您的href值设置为NotificationRedirect操作方法和notificationId querystring。差不多

<a href="YourControllerName/NotificationRedirect?notificationId=123">Notification tex</a>

此外,对于重定向,如果您显示的是应用程序内部的页面,那么您也可以考虑使用RealToToActudio方法。

显示您的JQYYRY代码。单击该通知时,请求将连同通知ID一起发送到控制器,其中所有的处理都被处理,然后重定向到指定的URL。它没有在jquery中处理。好的,向我们展示您拥有的代码,除非我们看到您的代码,否则我们无法考虑解决您的问题。public ActionResult NotificationRedirectint NotificationID{var notification=db.Notifications.FindNotificationID;…return Redirectnotification.Url;}谢谢。但是返回Redirectnotification.Url;它不能正常工作。然后在notification.url前面添加../返回重定向../+notification.url;现在它可以正常工作了。该方法需要一个解析url Ex:http://www.google.com. 为什么要在url之前附加../呢?如果您试图重定向到应用程序中的页面/视图,则应考虑使用ReDeTrToActudio方法。