मैं एक राय यह है कि 11 दृश्य में 2 IEnumerable मॉडल जोड़ने
@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>
}
दृश्य के साथ सफलतापूर्वक काम कर रहा था एक नियंत्रक
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");
}
}
}
के साथ हालांकि मैं इस तरह एक और टुकड़ा जोड़ना चाहते थे बनाया एक ही पृष्ठ पर, लेकिन एक अलग सामग्री पथ के साथ।
मैं इस पृष्ठ में एक और मॉडल कैसे जोड़ूं?
मैं सिर्फ एक नियंत्रक और देखें था, तो मैं एक ViewModel 2 वर्गों
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>
}
}
बनाने जब मैं अपने दृश्य @model IEnumerable<plantationmvc.Models.CommModel>
के रूप में यह कहते हैं कि यह नाम स्थान में मौजूद नहीं है में इस पारित करने के लिए कोशिश की सृष्टि की।
कि संकलन नहीं कर सकते। आपका * असली * कोड क्या है? – Amit
@ प्रवेश नियंत्रक दृश्य में जोड़ा गया; मॉडल स्निपेट वह है जो मैंने दूसरे मॉडल को जोड़ने और 'IENumerable' मॉडल को संपादित करने का प्रयास करने के लिए किया था। –
teachtyler