在1个视图中添加2个IEnumerable模型

tea*_*ler 8 c# model-view-controller razor

我创建了一个使用1个视图成功运行的视图

@model IEnumerable<string>
<ul>
    @foreach (var fName in Model)
    {
        var name = fName;
        var link = @Url.Content("~/Content/archives/mgamm/") + name.Replace(" ", "%20");

        <li style="list-style:none; font-size:1.2em;">
            <a href="@link">@name</a>
        </li>
    }
</ul>
@if (User.IsInRole("admin"))
{
    <div>
        @using (Html.BeginForm("Index", "Archives", FormMethod.Post, new { enctype = "multipart/form-data" }))
        {
            <input type="File" name="file" id="file" value="Choose File" />
            <button type="submit">Upload</button>
        }
    </div>
}
Run Code Online (Sandbox Code Playgroud)

带控制器

namespace plantationmvc.Controllers
{
    public class ArchivesController : Controller
    {
        //
        // GET: /Archives/
        public ActionResult Index()
        {
            var path = Server.MapPath("~/Content/archives/mgamm");

            var dir = new DirectoryInfo(path);

            var files = dir.EnumerateFiles().Select(f => f.Name);

            return View(files);
        }

        [HttpPost]
        public ActionResult Index(HttpPostedFileBase file)
        {
            var path = Path.Combine(Server.MapPath("~/Content/archives/mgamm"), file.FileName);

            var data = new byte[file.ContentLength];
            file.InputStream.Read(data, 0, file.ContentLength);

            using (var sw = new FileStream(path, FileMode.Create))
            {
                sw.Write(data, 0, data.Length);
            }

            return RedirectToAction("Index");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

但是我想在同一页面上添加这样的另一个代码段,但内容路径不同.

如何在此页面中添加其他模型?

我只有一个控制器和View,所以我创建了一个创建2个类的ViewModel

namespace plantationmvc.Models
{
    public class ArchivesViewModel
    {
        public CommModel Model1 { get; set; }
        public MeetModel Model2 { get; set; }
    }

    public class CommModel
    {
        public IEnumerable<CommModel>              
    }
    public class MeetModel 
    {
        public IEnumerable<MeetModel>
    }
}
Run Code Online (Sandbox Code Playgroud)

当我尝试将其传递到我的视图中时,因为@model IEnumerable<plantationmvc.Models.CommModel>它说它在命名空间中不存在.

Mst*_*san 8

{
 public class ArchivesViewModel
 {
    public IEnumerable<CommModel> Model1 { get; set; }
    public IEnumerable<MeetModel> Model2 { get; set; }
 }

 public class CommModel
 {
    //properties of CommModel 

 }
 public class MeetModel 
 {
   //properties of Meet Model
 }

 }
Run Code Online (Sandbox Code Playgroud)

并添加视图 @model plantationmvc.Models.ArchivesViewModel