를 원하는 이잖아, 내가 확인 한 경우 배열 목록을 할 필요가 없습니다, 당신은 당신의 배열에 전달할 수 있습니다 사람들이하는 몇 가지 .net 예제 컨트롤러에서보기로 데이터를 전달하는 강력한 형식보기. 이를 위해서는 해당 매개 변수가 설정되고 데이터를 전달할 수있는 모델이 있어야합니다.
내 모델을 가정
지금 내 컨트롤러가 홈이고 당신이 다음 컨트롤러가
과 같이 될 것이다 전통적인 방법으로 갈 경우 인덱스 페이지에서 로그인 페이지
이있는 사용자
namespace Mvc5Application.Models{
using System;
using System.Collections.Generic;
public partial class User
{
public System.Guid UserID { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public Nullable<System.Guid> OrgID { get; set; }
public virtual Organization Organization { get; set; }
}
}
입니다
[AllowAnonymous]
public ActionResult Index()
{
ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
return View();
}
[HttpPost]
public ActionResult Index(User model)
{
...[code for verification ]...
return View(model);
}
그리고 해당보기가 될 것입니다
,958,
그러나 기존의 모델을 따르고 싶지 않고보기 페이지에서 아무 것도 게시하지 않고 컨트롤러로 가져오고 설정이있는 경우 일부 작업을 수행 한 것처럼 일부 사용자 정의 작업을 수행하려는 경우 당신이보기에 데이터를 전달하고보기에 서로 다른 장소에 표시 할 데이터의 당신은 그런 컨트롤러가
public ActionResult Index()
{
ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
return View();
}
[HttpPost]
public ActionResult Index(FormCollection form)
{
String Username = form["Username"].ToString();
String Password = form["Password"].ToString();
Dictionary<string, string> MyList = new Dictionary<String, String>();
MyList.Add("name",Username);
MyList.Add("pass",Password);
ViewData["user"] = MyList;
return View();
}
될 것 ViewBag 또는을 ViewData
를 사용할 필요가 그리고보기
될 것입니다
@{
ViewBag.Title = "Home Page";
var list = ViewData["user"] as Dictionary<String, String>;
}
<h2>@ViewBag.Message</h2>
<div>
@if (list != null)
{
@Html.Label("User:-") @list["name"]
<br />@Html.Label("password:-") @list["pass"]
}
</div>
<p>
Please ligin/Register from here</p>
@using (Html.BeginForm("Home"))
{
<table>
<tr>
<td>User Name</td>
<td>@Html.TextBox("Username", ViewBag.CurrentFilter as string)</td>
</tr>
<tr>
<td>Password</td>
<td>@Html.TextBox("Password", ViewBag.CurrentFilter as string)</td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Save" class="btn btn-default" /></td>
</tr>
</table>
}
다음을 시도 : // itemslist는 ArrayList 유형입니다 - 일반이 아닌
목록 항목에 출력으로 System.String []이 표시됩니다. – Jake타입을 잊지 마라. foreach (ViewData [ "ItemsList"] in ArrayList- )) –
@Martin Booth ArrayList는 타입을 취하지 않는다. 그것은 내 편집 작업을해야합니다. – Pete