我在剃刀视图中有如下代码
<a href="@Url.Action("Details","Mycontr",new {id =16},Request.Url.Scheme)">
当我双击这个项目时,它被重定向到Url下面
http://localhost:49280/Mycontr/Section/@Url.Action(
但是预期的却是
http://localhost:49280/Mycontr/Details/16
以下是RouteConfig
routes.MapRoute( name: "Capsule",url: "Mycontr/Details/{id}",defaults: new { controller = "Mycontr",action = "Details",id = UrlParameter.Optional } ); routes.MapRoute( name: "Section",url: "Mycontr/Section/{id}",action = "Section",id = UrlParameter.Optional } );
请建议.
我缩小了这个问题. Html.Raw导致问题.我有类似的代码
@Html.Raw(HttpUtility.HtmlDecode(Model.sContent))
该变量包含生成的具有Ur.Action的html.如果我只是直接将html生成的代码放在razor视图中而不使用Html.Raw它工作正常.但是,如果我拿出Html.Raw运行时生成的html脚本显示为
<style type='text/css'></style><center><div style="width:460px;"><div style="width: 460px; float: left;"><div s...
有没有办法可以在不使用Html.Raw编码的情况下在变量中显示html脚本?
通过使用HtmlString代替字符串变量来保存生成的Html脚本,解决了一半问题,但HtmlString无法解码字符串中的@ Url.Action语法.
下面是我一直在努力使其工作的最新代码.请帮忙.
string templFile = string.Format("{0}\\DivTemplate.htm",path); HtmlDocument divDoc = new HtmlDocument(); StreamReader sRdr = new StreamReader(templFile,Encoding.UTF8); divDoc.Load(sRdr); XmlNodeList divs = regions.ChildNodes; IEnumerator enmrDivs = divs.GetEnumerator(); while (enmrDivs.MoveNext()) { XmlNode node = (XmlNode)enmrDivs.Current; string divId = node["DivId"].InnerText; string capId = node["CapsuleId"].InnerText; HtmlString sUrlAct = new HtmlString("@Url.Action(\"Capsule\",\"Publication\",new { id=\""+capId+"\" }))"); //string sUrlAct = "@Url.Action(\"Capsule\",new { id=\""+capId+"\"})"; string divFile = string.Format("{0}\\{1}.htm",path,divId); HtmlDocument divRgnDoc = new HtmlDocument(); StreamReader sR = new StreamReader(divFile,Encoding.UTF8); divRgnDoc.Load(sR); foreach (HtmlNode link in divRgnDoc.DocumentNode.SelectNodes("//a[@href]")) { link.Attributes.RemoveAll(); link.Attributes.Add("href",sUrlAct.ToString()); } HtmlNode divNode = divDoc.GetElementbyId(divId); divNode.AppendChild(divRgnDoc.DocumentNode.FirstChild.CloneNode(true)); sR.Close(); } sContent = new HtmlString (divDoc.DocumentNode.InnerHtml); sRdr.Close();