开发者

mvc3 RedirectToAction

Why isn't this working. It keeps telling me edit needs a EditStudyModel when I redirect in my Create method. A Redirect should do a get, right?

    public ViewResult Create()
    {
        var createStudyModel = new CreateStudyModel();
        return View(createStudyModel);
    }

    [HttpPost]
    public ActionResult Create(CreateStudyModel createStudyModel)
    {
        try
        {
            //TODO: Send CreateStudyCommand
            return RedirectToAction("Edit", new { scientificStudyId = new Guid("{1C965285-788A-4B67-9894-3D0D46949F11}") });
        }
        catch
        {
            return View(createStudyModel);
        }
    }

    [GET("ScientificStudy/Create/{scientificStudyId}")]
    public ActionResult Edit(Guid scientificStudyId)
    {
        //TODO: Query real model
        var model = new EditStudyModel() {StudyNr = "T01", StudyName = "Test"};
        return View(model);
    }

    [HttpPost]
    public ActionResult Edit(EditStudyModel editStudyModel)
    {
        try
        {
            //TODO: Send UpdateStudyCommand
            return RedirectT开发者_开发知识库oAction(""); //TODO: Terug naar Studie lijst
        }
        catch
        {
            return View(editStudyModel);
        }
    }


You're returning a redirect with a URL as a string, the controller isn't able to parse the GUID and convert it back to a guid object, so it's not able to resolve the correct method signature to use. Change it to:

return RedirectToAction("Edit", new { scientificStudyId = "{1C965285-788A-4B67-9894-3D0D46949F11}" });

and

public ActionResult Edit(string scientificStudyId)


I found the issue. I copy paste my create.cshtml to edit.cshtml Forgot to change the first line: @model Website.Models.CreateStudyModel --> to --> @model Website.Models.EditStudyModel

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜