Umbraco 7 HttpPost空模型属性

时间:2018-12-19 12:21:06

标签: model-view-controller umbraco

我在umbraco中创建了一个表单,使用Home HttpGet操作显示Home.cshtml。在视图中,我有umbraco开始表单,并通过它重定向到Home HttpPost操作。发生重定向,但在UserName模型中返回null。怎么解决呢? 控制器:

        public ActionResult Home(RenderModel model)
    {
        var vm = new ViewModel<Home>(model);
        vm.CustomModel = new Models.Home();
        vm.CustomModel.UserName = "Slawek";
        return View(vm);
    }
    [System.Web.Mvc.HttpPost]
    [ActionName("Home")]
    public ActionResult Home(Home model)
    {
        var m = model;
        return RedirectToAction("Home");
    }
}

型号:

    public class Home
{
    public string UserName { get; set; }
}

ViewModel:

    public class ViewModel<TModel> : RenderModel
{
    public ViewModel(RenderModel model) : base(model.Content, model.CurrentCulture) { }

    public TModel CustomModel { get; set; }
}

查看:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<UmbracoTest9.Models.ViewModel<UmbracoTest9.Models.Home>>
@{
    Layout = "Master.cshtml";
}
@Model.Content.GetPropertyValue("pageTitle")
@using (Html.BeginUmbracoForm("Home", "Home"))
{
    @Html.EditorFor(x => x.CustomModel.UserName)
    <input type="submit" />
}

0 个答案:

没有答案