MVC在新视图中显示URL列表 [英] mvc display list of urls at new view

查看:94
本文介绍了MVC在新视图中显示URL列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

0下投最爱
分享[fb]分享[tw]


在这里的MVC初学者,每条建议/帮助都值得赞赏.我想要实现的是,我在控制器中有一个URL及其锚标记的列表.我想将它们发布到新视图.在该新视图中,它们将根据其名称显示在排序列表中.到目前为止,我已经有了名称和锚文本,我打算做的就是将它们放在ViewData中,并在新视图中传递它.

这就是我在控制器中的功能:

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:

Dictionary<string, string> list = ExtractURL(content);
                return View(new Website(list, "Addresses"));



词典包含URL和提取的URL中的锚文本.并在视图中:



The dictionary contains the url and the anchor text from the extracted url. And in the view:

<%=ViewData["Addresses"] %>



现在,我应该在新视图中如何用url和锚文本填充已排序的列表?感谢您的帮助.

谢谢,Laziale



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

推荐答案

简单的方法是返回带有排序列表的View.

您可以使用排序算法手动或使用SortedDictionary类System.Collection.Generic命名空间自动对返回视图的集合进行排序.

默认情况下,Herez转换后的代码按返回列表的排序列表:
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:
using System.Collection.Generic;
....
....
{
   Sorteddictionary<string,> list - new SortedDictionary<string,string>();
   list = ExtractURL(content;
   return View(new Website(list, "Addresses"));
}


默认情况下,第一个字符串被视为Key并在每个元素的插入上自动排序.我们将找到所需的解决方案.


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.


这篇关于MVC在新视图中显示URL列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆