Asp.net mvc 5 MVC 5 HttpPost:更新表

Asp.net mvc 5 MVC 5 HttpPost:更新表,asp.net-mvc-5,Asp.net Mvc 5,@使用Html.begin { @Html.DisplayNameFormodel=>model.ID @Html.DisplayNameFormodel=>model.PracticeExercise.Muscle @Html.DisplayNameFormodel=>model.PracticeExercise.Execrcise @Html.DisplayNameFormodel=>model.PracticeExercise.PlannedSets @Html.DisplayNameFo

@使用Html.begin { @Html.DisplayNameFormodel=>model.ID @Html.DisplayNameFormodel=>model.PracticeExercise.Muscle @Html.DisplayNameFormodel=>model.PracticeExercise.Execrcise @Html.DisplayNameFormodel=>model.PracticeExercise.PlannedSets @Html.DisplayNameFormodel=>model.PracticeExercise.PlannedRepeats @Html.DisplayNameFormodel=>model.PracticeExercise.Pause 砝码 重复 @模型中的每个var项 { @Html.DisplayFormodelItem=>item.ID @Html.DisplayFormodelItem=>item.PracticeExercise.Muscle @Html.DisplayFormodelItem=>item.PracticeExercise.Execrcise @Html.DisplayFormodelItem=>item.PracticeExercise.PlannedSets @Html.DisplayFormodelItem=>item.PracticeExercise.PlannedRepeats @Html.DisplayFormodelItem=>item.PracticeExercise.Pause @Html.EditorFormodelItem=>item.Weights1, 新的{htmlAttributes=new{@class=formcontrol} @Html.EditorFormodelItem=>item.weights, 新的{htmlAttributes=new{@class=formcontrol} @Html.EditorFormodelItem=>item.Weights3, 新的{htmlAttributes=new{@class=formcontrol} @Html.EditorFormodelItem=>item.weights, 新的{htmlAttributes=new{@class=formcontrol} @Html.EditorFormodelItem=>item.weights, 新的{htmlAttributes=new{@class=formcontrol} @Html.EditorFormodelItem=>item.Repeats1, 新的{htmlAttributes=new{@class=formcontrol} @Html.EditorFormodelItem=>item.Repeats2, 新的{htmlAttributes=new{@class=formcontrol} @Html.EditorFormodelItem=>item.Repeats3, 新的{htmlAttributes=new{@class=formcontrol} @Html.EditorFormodelItem=>item.repeats, 新的{htmlAttributes=new{@class=formcontrol} @Html.EditorFormodelItem=>item.Repeats5, 新的{htmlAttributes=new{@class=formcontrol} } } 见评论:

不能使用foreach循环为集合中的项生成控件。参考此答案–斯蒂芬·穆克2015年8月26日10:31


谢谢你的链接!for循环的提示非常好。但现在我遇到了一个问题,每次我按下submit按钮,它都会捕获列表中的第一个元素并将其提供给post控制器2015年8月27日下午14:47


如果您使用包含for循环和submit按钮的单表单,它将发回整个集合,而不是一个。注意,不能同时保存单个记录和记录列表。尽管您可以使用第二个表单来创建新记录,并将其发回不同的控制器方法Stephen Muecke 2015年8月27日23时22分

不能使用foreach循环为集合中的项目生成控件。请参考链接,谢谢!for循环的提示非常好。但现在我遇到了一个问题,每次我按下submit按钮,它都会捕获列表中的第一个元素并将其交给post控制器。如果使用包含for循环和submit按钮的单个表单,它将发回整个集合,而不是一个。注意,不能同时保存单个记录和记录列表。虽然您可以使用第二个表单来创建新记录,并将其发回其他控制器方法。但是,如果您不复制和粘贴所有注释,而是详细说明您的答案以显示解决方案,该怎么办?