我不能讓我的指數()操作來傳遞一個有效的模式,我的評論()動作是什麼(模型),並返回RedirectToAction返回查看的區別(「視圖名」,模型)
.. 。的ActionResult指數()...
else
{
return RedirectToAction("Review", wizard); <--wizard is a valid object here....
}
的ActionResult評論()
public ActionResult Review()
{
return View(_wizard); <-- THis is always null.
}
更新: 這裏是我的整個控制器。我想讓用戶從嚮導索引到評論頁面,最後到達實際保存數據的傳輸頁面。我的最後一塊包裹着我的頭腦,真的有問題。當你習慣了asp classic時,你必須從頭開始明確地編寫所有的東西,這很難適應MVC3中的Magic繼承。所以,我敢打賭,我正在編寫大量沒有用的代碼。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using mvc3test.Models;
using Microsoft.Web.Mvc;
using System.Web.Mvc;
using mvc3test.Services;
namespace mvc3test.Controllers
{
public class WizardController : Controller
{
private WizardViewModel wizard = new WizardViewModel();
private DR405DBContext db;
public WizardController(IDBContext dbContext)
{
db = (DR405DBContext)dbContext;
}
public WizardController()
{
db = new DR405DBContext();
}
public ActionResult Index()
{
wizard.Initialize();
return View(wizard);
}
[HttpPost]
public ActionResult Index([Deserialize] WizardViewModel wizard, IStepViewModel step)
{
wizard.Steps[wizard.CurrentStepIndex] = step;
if (ModelState.IsValid)
{
if (!string.IsNullOrEmpty(Request["next"]))
{
wizard.CurrentStepIndex++;
}
else if (!string.IsNullOrEmpty(Request["prev"]))
{
wizard.CurrentStepIndex--;
}
else
{
return View("Review", wizard);
}
}
else if (!string.IsNullOrEmpty(Request["prev"]))
{
wizard.CurrentStepIndex--;
}
return View(wizard);
}
[AllowAnonymous]
public ActionResult Review(WizardViewModel model)
{
return View(model);
}
[AllowAnonymous]
[HttpGet]
public ActionResult Review(Int32 ID)
{
var service = new DR405Service(db);
var myWizard = service.WireUpDataModelToViewModel(service.DBContext.dr405s.Single(p => p.ID == ID));
return View(myWizard);
}
public ActionResult Transmit()
{
var service = new DR405Service(db);
service.Wizard = wizard;
service.Save();
return View();
}
}
}
您是否收到錯誤?該對象是否以其傳入視圖的方式存在,或者在它通過控制器之前是否爲空?如果您提供的信息多於「This does not work」,那麼它更容易幫助= D – BentOnCoding
http://www.asp.net/mvc>學習資源>控制器基礎 –
@Chris如果我能夠理解由微軟你認爲我會問這裏嗎? –