2011-04-17 63 views
1

我使自己的消耗饲料小用户控件的代码,所述用户控制装置看起来像这样Html.RenderPartial及具有相同ID错误

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<SyndicationFeed >" %> 

<%foreach (var rss in ViewData.Model.Items) 
    { 
     Response.Write("<div id={0}><a href={1} target=\"_blank\" /> <strong>{2}</strong></div>", 
      rss.Links[0].Uri.OriginalString, rss.Title.Text, rss.Title.Text); 
     Response.Write("<div>" + rss.Summary.Text.Truncate(100) + "</div>") 
    }%> 

的RssController的代码看起来像这样多个控件

public virtual ActionResult Index() 
{ 
    string feedUrl = @"http://wdfw.wa.gov/news/newsrss.php"; 

    using (XmlReader reader = XmlReader.Create(feedUrl)) 
    { 
     SyndicationFeed rss = SyndicationFeed.Load(reader); 

     return View(rss); 
    }    
} 

我叫它的Site.Master像这样

<%Html.RenderPartial("Index", Model);%> 

我也试过

<%Html.RenderPartial("Index", ViewData.Model);%> 

所有导致这个这个错误:

Multiple controls with the same ID 'ctl00' were found. Trace requires that controls have unique IDs.

有人可以帮我找出我要去哪里错了,请:)

+0

禁用跟踪。 – SLaks 2011-04-17 17:28:54

回答

0

你可以尝试使用Html.RenderAction(”索引“,”Rss“)而不是Html.RederPartial?当ViewEngine调用Html.RenderAction时,您的Index操作中的所有代码都会执行,并且具有rss数据的Model会转到Index视图以生成标记。为什么你使用Response.Write,鉴于你可以把HTML标签,这个标记将被插入你调用Html.RenderAction的地方。希望它会对你有所帮助,如果没有,对不起,至少我已经试过了))

祝你好运, 迪马。

+0

昏暗我试过你的选择,并且我收到此消息编译器错误消息:CS0121:该调用在以下方法或属性之间不明确:'Microsoft.Web.Mvc.ViewExtensions.RenderAction(System.Web.Mvc.HtmlHelper,string,string )'和'System.Web.Mvc.Html.ChildActionExtensions.RenderAction(System.Web.Mvc.HtmlHelper,string,string)' – PsychoCoder 2011-04-17 19:31:48

+0

@PsychoCoder它是不正确的,因为我可以从您的评论中看到..为什么您标记它作为答案? – RredCat 2012-12-06 14:09:16

相关问题