maz*_*ztt 0 asp.net asp.net-mvc
用户控制
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<%
using (MvcApplication1.Models.EgovtDataContext _model = new MvcApplication1.Models.EgovtDataContext())
{
%>
<% foreach(var md in MvcApplication1.Models.) { %>
<% if (md.ParentId == 0)
{ %>
<% } %>
<% } %>
<%} %>
Run Code Online (Sandbox Code Playgroud)
FeatureRepository类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MvcApplication1.Models
{
public class FeaturesRepository
{
EgovtDataContext db = new EgovtDataContext();
public IEnumerable<Feature> GetAllFeatures()
{
List<Feature> Features = new List<Feature>();
Feature feature = new Feature();
var AllParentFeatures = FeaturesByParentId(0);
foreach (Feature frParentCategory in AllParentFeatures)
{
feature.int_FeatureId = frParentCategory.int_FeatureId;
feature.vcr_FeaturesName = frParentCategory.vcr_FeaturesName;
feature.int_ParentId = frParentCategory.int_ParentId;
Features.Add(feature);
var AllChildFeaturesofthatParent = FeaturesByParentId(frParentCategory.int_FeatureId);
int AllChildFeaturesofthatParentCount = AllChildFeaturesofthatParent.Count();
foreach (Feature frChildCategory in AllChildFeaturesofthatParent)
{
feature.int_FeatureId = frParentCategory.int_FeatureId;
feature.vcr_FeaturesName = frParentCategory.vcr_FeaturesName;
feature.int_ParentId = frParentCategory.int_ParentId;
Features.Add(feature);
}
}
return Features;
}
}
}
Run Code Online (Sandbox Code Playgroud)
1)这是在上面的方法中正确完成的公共IEnumerable GetAllFeatures()吗?并正确编写了方法?2)我想在上面的控件中调用GetAllFeatures方法?我该怎么办?3)应该在共享文件夹中创建用户控制器?什么是共享文件夹?
创建控制器操作
public ActionResult All()
{
return View(new FeaturesRepository().GetAllFeatures());
}
Run Code Online (Sandbox Code Playgroud)
并更改您的usercontrol声明
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<Feature>>" %>
<% foreach(var md in Model)
{ %>
<% if (md.ParentId == 0)
{ %>
//blabla
<% } %>
<% } %>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
167 次 |
| 最近记录: |