2016-04-25 91 views
-1

我有一个通知控制器,该控制器表像创建一个URL重定向到URL中Asp.Net MVC

public void EnterData() 
{ 
    Notification notify = new Notification(); 
    notify.Url = "../Controller/Action/1?dataID=2" 
    db.Notification.Add(notify); 
    db.SaveChanges(); 
} 

保存数据保存数据后,我当用户点击进入该页面通知。

public ActionResult Message(id) 
{ 
    Notification notify = db.Notification.Find(id); 
    . 
    . 
    return Redirect(notify.Url); 
} 

它在一些页面中工作,但是从某些页面重定向会导致错误。
在此先感谢。

+3

有什么错误? – ChrisBint

+0

该网址无法正确重定向。重定向后url为“http://www.sample.com/controller/controller/action”。 – anand

+0

网址数据可能会有所不同。我最好有一个tble的动作链接 – anand

回答

-2

您可以使用RedirectToAction

return RedirectToAction("Action","Controller", new RouteValueDictionary( 
    new {parameterName = Some Value}) 
); 
+0

我必须将网址保存为表格中的操作链接,点击它时,它应该简单地重定向到页面。 – anand

+0

@anand:那么会是什么问题? – Tushar

+0

控制器和操作和参数可能会有所不同。所以我不得不将链接保存为Url.Action(“”)这样的事情。当我重定向时,我不应该像你一样使用。它应该像重定向(Url); – anand