开发者

ASP.NET MVC Dynamic RenderActions in jquery tabs

Ok, so, that title is a mouthfull... But, I reckon you understand what I'm trying to do.

I have a page which contains the jquery tabs control, and I render the different tabs by looping through my model. Now, the divs (that are "linked" to those tabs) are also created with the same loop. Hence I have equal tabs + divs connected to those tabs.

The problem is, that it's only the first RenderAction gets called, all the others are just the same.

The code that loops the renderactions:

foreach (var domain in Model.Domains)
{ %>
    <%= String.Format(@"<div id=""domai开发者_开发百科n_{0}"">", domain.ID)%>
        <%= Html.Encode(domain.ID) %>
        <% Html.RenderAction("DomainView", "Person", new { domainid = domain.ID }); %>

    </div>
<% } %>

So, each div has an id of "domain_NUMBER" where of course the number is looped. And the renderaction calls the "DomainView" Action in my controller that takes a "domainid" parameter.

Optimistically, I thought this would work, but, I guess I'm wrong...


If I understand you correctly, you're getting, say, 3 divs, but they're all the same.

By same you could mean 2 things:

1) If you mean that all the divs are named "div_1", then you have 3 domains with the same domainid and there's an issue with the way you add domains to your model

2) If you mean that the divs are named differently but the content is the same,

You need to set a breakpoint at the DomainView action of the Person controller. This will let you see what domainid is being passed in. Because the code itself looks fine. The issue probably has to do with routing. For example, the DomainView action takes an ID parameter but you're passing DOMAINID so ID is just defaulting to 0 which means all the divs have the same content


Statichippo, indeed, it had something to do with my routevalues.

Seeing I'm not the developer that made the routemap, I "forgot" to check these. Once I formulated my URL's to use querystring, all worked well!

In the current project, it's not allowed to add/modify route values, so I had to find a workaround.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜