I would like to take the data entered into a custom MVC form and display it in a different view.
The class has the following variable:
IList<string> _pagecontent = new List<string>();
The following action takes a FormCollection object, validates it, and passes it to the Preview view as a list:
[Authorize(Roles = "Admins")] [ValidateInput(false)] [AcceptVerbs(HttpVerbs.Post)] public ActionResult UpdateContent(FormCollection collection) { if (ModelState.IsValid) { string PageToInsert = collection["PageToInsert"]; string PageHeader = collection["PageHeader"]; string PageBody = collection["PageBody"];
The Preview view has the following directive for passing a strongly typed List object:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Template.Master" Inherits="System.Web.Mvc.ViewPage<List<string>>" %>
I would expect that I could use the Model object to get my data, but, alas, I can not. In the next line, I get an error index out of bounds exception, indicating that the index must be non-negative and smaller than the size of the collection:
<% if (Model[0].ToString() == "0") { %>
And some strange parameters are added to the URL, as it allows http://localhost:1894/Admin/Preview?Capacity=4&Count=3
I have two questions:
- When I call RedirectToAction and pass it my list, why is it not available in the representation of the model object?
- What is the correct way to do what I'm trying to do, namely pass a collection of strings in a view to display there?
c # asp.net-mvc redirecttoaction
splatto Mar 23 '09 at 3:27 2009-03-23 ββ03:27
source share