我不能让我的指数()操作来传递一个有效的模式,我的评论()动作是什么(模型),并返回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如果我能够理解由微软你认为我会问这里吗? –