R
Roger Frost
Greetings,
I'm coming from a WinForms background and diving into ASP.Net. I'm using:
C#, VS2010, .Net 4.0, ASP.Net, MVC 2.
What I want to do is get a string[] of roles in the controller with:
string[] currentUsersRoles = Roles.GetRolesForUser(User.Identity.Name);
Then I want to attach this to the ViewData object (also in the controller):
ViewData["CurrentUsersRoles"] = currentUsersRoles;
Now, in the View I want to bind a Repeater to the array I fed to ViewData.
Something
like:
<asp:Repeater ID="CurrentUsersRoles" runat="server" DataSourceID="[WHAT GOES
HERE?]">
<HeaderTemplate>
<b>Account Roles:</b>
<br />
</HeaderTemplate>
<ItemTemplate>
<%# [WHAT GOES HERE?] %>
<br />
</ItemTemplate>
</asp:Repeater>
I want to do this without code behind (which I can already do with my
limited knowledge)
because using code behind defeats the purpose of using MVC in the first
place, but that's
just me. Anyhow, this should be easy right? The Repeater exists for the
sole purpose of
displaying collections efficiently, yes? So is there a collection any
simpler or more fundamental
than an array? I suspect some casting will be needed from object back to
string[], but I don't know
where to begin, all I have now is a hammer and they all look like nails to
me.
I've been googling this for hours, but the posts I've seen all want to use
code behind to
acomplish this except this one:
http://forums.asp.net/t/1257598.aspx
I believe she is on the right track...at least it looks good to me, but
being the newbie that I am, I'm
stuck on the line:
<ext:ViewDataSource ID="MyViewDataSource" runat="server"
ViewDataKey="Computers" />
Because evidently "ext" doesn't mean anything in asp.net.
But, back to my point about simple-array-binding-repeater-thingamajigs, this
approach
seems like overkill for such a trivial task anyhow.
Can someone please enlighten me? All productive answers will be extremely
appreciated!
Thanks,
Roger
I'm coming from a WinForms background and diving into ASP.Net. I'm using:
C#, VS2010, .Net 4.0, ASP.Net, MVC 2.
What I want to do is get a string[] of roles in the controller with:
string[] currentUsersRoles = Roles.GetRolesForUser(User.Identity.Name);
Then I want to attach this to the ViewData object (also in the controller):
ViewData["CurrentUsersRoles"] = currentUsersRoles;
Now, in the View I want to bind a Repeater to the array I fed to ViewData.
Something
like:
<asp:Repeater ID="CurrentUsersRoles" runat="server" DataSourceID="[WHAT GOES
HERE?]">
<HeaderTemplate>
<b>Account Roles:</b>
<br />
</HeaderTemplate>
<ItemTemplate>
<%# [WHAT GOES HERE?] %>
<br />
</ItemTemplate>
</asp:Repeater>
I want to do this without code behind (which I can already do with my
limited knowledge)
because using code behind defeats the purpose of using MVC in the first
place, but that's
just me. Anyhow, this should be easy right? The Repeater exists for the
sole purpose of
displaying collections efficiently, yes? So is there a collection any
simpler or more fundamental
than an array? I suspect some casting will be needed from object back to
string[], but I don't know
where to begin, all I have now is a hammer and they all look like nails to
me.
I've been googling this for hours, but the posts I've seen all want to use
code behind to
acomplish this except this one:
http://forums.asp.net/t/1257598.aspx
I believe she is on the right track...at least it looks good to me, but
being the newbie that I am, I'm
stuck on the line:
<ext:ViewDataSource ID="MyViewDataSource" runat="server"
ViewDataKey="Computers" />
Because evidently "ext" doesn't mean anything in asp.net.
But, back to my point about simple-array-binding-repeater-thingamajigs, this
approach
seems like overkill for such a trivial task anyhow.
Can someone please enlighten me? All productive answers will be extremely
appreciated!
Thanks,
Roger