Controller控制器代码,用于返回List
public void FlashGet(String browserAddr) { //创建models FlashGet flashGet = new FlashGet(); //根据url是否为空判断定向到页面 ViewData["test"] = "url is:"+browserAddr; if (browserAddr==null) { RenderView("HowTo"); } else { List<String> Result=flashGet.GetSWFS(browserAddr); //返回结果给list ViewData["list"] = Result; RenderView("SWFList"); } }
View视图代码,遍历List
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" CodeBehind="SWFList.aspx.cs" Inherits="FlashSaver.Views.Home.SWFList" %> <%@ Register TagPrefix="m" Namespace="FlashSaver.App_Code" %> <asp:Content ID="Content1" ContentPlaceHolderID="MainContentPlaceHolder" runat="server"> <%=ViewData["test"]%> <% foreach (String path in (ViewData["list"] as List<String>)) { Response.Write(path+"<br/>"); } %> </asp:Content>