MVC - Html.BeginForm。我的动作方法没有收到参数

时间:2015-03-17 08:36:03

标签: asp.net-mvc razor

我正在尝试将数据保存到我的模型中。 这是我的Action方法:

...   

        [HttpPost]
        public ActionResult UpdateSectionInformation(SectionInformation sectionInformation) {
            ViewBag.SectionUpdatedSuccesfully = true;
            SectionInformation s = sectionInformation;
            // Save settings to database.
            using (var session = MvkStorage.GetSession()) {
                var client = new MvkSectionStorageHandler(session);
                try {
                    client.SaveOrUpdateSection(s.Section);                   

                    client.SaveOrUpdateSectionReschedulingRelations(s.RescheduleFromRelations);
                    client.SaveOrUpdateSectionReschedulingRelations(s.RescheduleToRelations);
                } catch (Exception) {
                    ViewBag.SectionUpdatedSuccesfully = false;
                }
            }

            return View("Index", s);
        }

这是Html.BefinForm“声明”(控制器名称是SectionController):

@using(Html.BeginForm("UpdateSectionInformation", "Section", FormMethod.Post)) {

似乎问题是UpdateSectionInformation得到一个空模型。我该怎么解决?我是MVC的新手,我真的不知道调用UpdateSectionInformation的地方。 我见过Html.HiddenFor的内容,我应该在这里使用吗?:

@for (int i = 0; i < Model.RescheduleFromRelations.Count(); i++ ) {


                var relation = Model.RescheduleFromRelations.ElementAt(i);
                var relationId = relation.FromSection.ToString() + relation.ToSection.ToString();
                ...

编辑:感谢评论解决了问题

0 个答案:

没有答案
相关问题