1

I am trying to render multiple Views using a loop like this

@model IEnumerable<RamtaJogi.Web.Razor.Controllers.IMenuRenderer>

@foreach (var item in @Model)
{
    {@Html.RenderPartial(@item.ViewName, @item.ViewData);}
     <br />
}     

here is my IRenderer

public interface IMenuRenderer     
{
    string ViewName { get; }
    object ViewData { get; }
}

But it throws an error CS1502: The best overloaded method match for 'System.Web.WebPages.WebPageExecutingBase.Write(System.Web.WebPages.HelperResult)' has some invalid arguments

I pass a collection of objects of type IMenuRenderer to my view.

Any idea what is wrong with my codes. Can someone help here.

Regards

Parminder

1
  • Can you post your implementation of IRenderer/IMenuRenderer ? Commented May 1, 2011 at 5:38

2 Answers 2

2

You have too many @ characters.

You should only use @s to enter the foreach.
Since RenderPartial returns void, you cannot print its result with an @.
Parameters also never get @s.

Change your code to

@model IEnumerable<RamtaJogi.Web.Razor.Controllers.IMenuRenderer>

@foreach (var item in Model)
{
    @Html.Partial(item.ViewName, item.ViewData)
     <br />
}     
Sign up to request clarification or add additional context in comments.

Comments

0

You can create a custom helper.I think this will help you. ASP.NET MVC: Custom Html Helpers in Razor

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.