通过单个控制器动作在序列中呈现html

时间:2017-04-22 05:06:51

标签: c# asp.net-mvc

有没有办法通过相同的控制器动作一个接一个地显示多个字符串?

例如我想在加载并显示在视图上的paraOne字符串后显示paraTwo字符串,在视图上加载paraTwo之后显示paraThree字符串,依此类推。

Public ActionResult ChapterOne()
{

string paraOne = "This is paragraph one ";

string paraTwo = "This is paragraph two";

string paraThree = "This is paragraph three";

string paraFour = "This is paragraph four";

return View();

}

2 个答案:

答案 0 :(得分:2)

您可以使用List<string>按顺序添加段落

var listparas= new List<string>();

listparas.Add("This is paragraph one ");

listparas.Add("This is paragraph two");

listparas.Add("This is paragraph three");

listparas.Add("This is paragraph four");

return View(listparas);

并在view

@model List<string>

 foreach (var paragraph in Model)
    {
         <p>@paragraph</p>
    }

如果您使用的是viewmodel,则可以添加

    public List<string> ParaList { get; set; }

您可以在Model.ParaList

中按foreach进行迭代

答案 1 :(得分:0)

创建var app = angular.module("playlists", []); app.controller("mainController", ['$scope','$http','$compile','$timeout', function($scope, $http, $compile, $timeout) { $scope.has_flash = function() { //function to detect if Flash is installed and enabled //prompt user to install/enable Flash if not already installed //returns a bool } //instantiates the Napster Web API Player Napster.player.on('ready', function(e) { Napster.member.set({accessToken: 'oauth access token'}); // If not set earlier Napster.player.auth(); } $scope.play_napster_track = funtion(song_id) { Napster.player.play(song_id); //plays a track using the Napster Web API } )};

model

public class Paragraph { public string paraOne { get; set; } public string paraTwo { get; set; } public string paraThree { get; set; } public string paraFour { get; set; } }

Action

public ActionResult ChapterOne() { var paragraph = new Paragraph { paraOne = "This is paragraph one ", paraTwo = "This is paragraph two", paraThree = "This is paragraph three", paraFour = "This is paragraph four" }; return View(paragraph); }

View