Click here to Skip to main content
14,877,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
0 down vote favorite
share [fb] share [tw]


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:
C#
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:

HTML
<%=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
Posted
Updated 11-Sep-11 11:32am
v2
Comments
Sergey Alexandrovich Kryukov 11-Sep-11 17:33pm
   
Please see how to use <pre> tags. Use "Improve question" to see the source HTML code I edited for you.
--SA

1 solution

Simple way is to return the View with the sorted list.

You can sort the collection of return view either manually using sort algorithm or automatically using SortedDictionary class System.Collection.Generic namespace.

Herez the converted code by default sorted list on return View:
C#
using System.Collection.Generic;
....
....
{
   Sorteddictionary<string,> list - new SortedDictionary<string,string>();
   list = ExtractURL(content;
   return View(new Website(list, "Addresses"));
}

By default, the first string is treated as Key and sorted automatically on each elements' insert. We'll get the solution, what we are looking for.
   
Comments
laziale 12-Sep-11 4:19am
   
Thanks for helping me out, I would like to know how to display that list in the view? How can I use the list in the view part to display correctly the data. In the data I have url, example "index.html" and their anchor tag, example "home".
Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900