Reputation: 8225
MVC beginner over here and every advice/help is appreciated. What I am trying to achieve is I have a list of url's and their anchor tags in a controller. I want to post them to a new view. In that new view they will be displayed in a sorted list according to their name. So far, I have the name and the anchor text, and what I am planning to do is to put them in a ViewData and pass that in the new view.
This is what I have in the controller:
Dictionary<string, string> list = ExtractURL(content);
return View(new Website(list, "Addresses"));
The dictionary contains the url and the anchor text from the extracted url. And in the view:
<%=ViewData["Addresses"] %>
What should I do now at the new view to populate the sorted list with the url and the anchor text? Every help is appreciated. Thanks, Laziale
Upvotes: 1
Views: 807
Reputation: 16848
If you want that dictionary returned to your view, you are probably best to actually assign it to your ViewData:
ViewData["Addresses"] = list;
return View();
This takes the Dictionary object you populate (presumably) in the ExtractURL(content) method and makes it available for use in your view.
Your view would then iterate over each item in your list:
<ul>
<% foreach(var Item in ViewData["Addresses"] as Dictionary<string, string>) {
%>
<li>// Show my Item.Properties here</li>
<% }
%>
</ul>
Upvotes: 1