我正在寻找适当的语法。我正在使用MVC,在我看来,我需要循环遍历模型,因为我需要在不同的方面做一些其他的事情。我在这里是一个新手,并通过大量的帖子看,但没有找到语法。 下面是代码,它的工作原理:如何用for循环替换foreach循环
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<MvcMysurvey.Models.Mysurvey>>" %>
<% foreach (var item in Model) {%>
<%: Html.HiddenFor(m => item.ID) %>
And here is the code I need the syntax for to make it working:
<% for (int i = 0; i < Model.Count(); i++) {%>
<%: Html.HiddenFor(m => m[i].ID) %>
使用foreach有什么问题? –
它只是你缺少的“循环计数”吗?这就是为什么你想要循环而不是? 顺便说一下,For循环语法对我来说似乎没问题。有什么问题 ? – Shenaniganz
为什么一个foreach不是你所需要的?这两个是非常相似的 –