नहीं है, मुझे अपने मुद्दे के लिए कोई समाधान नहीं मिला, मैंने कई विकल्पों की कोशिश की है लेकिन मैं इसे हल नहीं कर सका।आईनेमरेबल त्रुटि प्राप्त करना: सीएस 1061 में सी # एएसपी.नेट एमवीसी 5
मैं पहले मॉडल के साथ अपना डेटाबेस जेनरेट करता हूं, इसके बाद मैंने दृश्य (इंडेक्स, बनाएं, संपादित करें, हटाएं ..) उत्पन्न करने के लिए मचान का उपयोग किया है। मॉडल के साथ एकमात्र दृश्य (इंडेक्स) IENumerable का उपयोग करें।
सूचकांक देखें था:
@model IEnumerable<CAD_CMDBv2.Models.Location>
@{
ViewBag.Title = "Location's Management";
}
<h2>All Locations</h2>
<p>
@Html.ActionLink("Create Location", "Create")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.Location.site_name)
</th>
<th>
@Html.DisplayNameFor(model => model.Location.country_name)
</th>
<th>
@Html.DisplayNameFor(model => model.Location.region_name)
</th>
<th></th>
</tr>
@foreach(var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Location.site_name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Location.country_name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Location.region_name)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.Location.location_id }) |
@Html.ActionLink("Details", "Details", new { id = item.Location.location_id }) |
@Html.ActionLink("Delete", "Delete", new { id = item.Location.location_id })
</td>
</tr>
}
</table>
मैं datasearch के लिए एक अतुल्यकालिक रूप सम्मिलित करना चाहते हैं, ताकि हो जाता है:
@model IEnumerable<CAD_CMDBv2.Models.RechercheLocationViewModel>
@{
ViewBag.Title = "Location's Management";
}
<h2>All Locations</h2>
<p>
@Html.ActionLink("Create Location", "Create")
</p>
@using (Html.BeginForm("Search", "Restaurant", FormMethod.Get))
{
@Html.TextBoxFor(r => r.Recherche)
<input type="submit" value="Rechercher" />
<p>Search Results </p>
if (Model.ListeLocations.Count == 0)
{
<p> No Results but you can create it !</p>
}
else
{
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.Location.site_name)
</th>
<th>
@Html.DisplayNameFor(model => model.Location.country_name)
</th>
<th>
@Html.DisplayNameFor(model => model.Location.region_name)
</th>
<th></th>
</tr>
@foreach(var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Location.site_name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Location.country_name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Location.region_name)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.Location.location_id }) |
@Html.ActionLink("Details", "Details", new { id = item.Location.location_id }) |
@Html.ActionLink("Delete", "Delete", new { id = item.Location.location_id })
</td>
</tr>
}
</table>
}
}
मैं के लिए एक दृश्य मॉडल वर्ग को जोड़ने में मॉडल को संशोधित किया है इंडेक्स व्यू को पैरामीटर को ले कर मॉडल देखें मॉडल के रूप में लेने के लिए अनुमति दें और खोज पैरामीटर का उपयोग करें:
//------------------------------------------------------------------------------
// <auto-generated>
// Ce code a été généré à partir d'un modèle.
//
// Des modifications manuelles apportées à ce fichier peuvent conduire à un comportement inattendu de votre application.
// Les modifications manuelles apportées à ce fichier sont remplacées si le code est régénéré.
// </auto-generated>
//------------------------------------------------------------------------------
namespace CAD_CMDBv2.Models
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
public partial class Location
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public Location()
{
this.User = new HashSet<User>();
this.host = new HashSet<Host>();
this.client_catia = new HashSet<Client_catia>();
this.client_smartam = new HashSet<Client_smarteam>();
}
public int location_id { get; set; }
[Display(Name = "Site's Name")]
public string site_name { get; set; }
[Display(Name = "Country's Name")]
public string country_name { get; set; }
[Display(Name = "Region's Name")]
public string region_name { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<User> User { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Host> host { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Client_catia> client_catia { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Client_smarteam> client_smartam { get; set; }
}
public class RechercheLocationViewModel : IEnumerable<Location> {
public string Recherche {get; set;}
public Location Location { get; set; }
public List<Location> ListeLocations;
public IEnumerator<Location> GetEnumerator()
{
return ListeLocations.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return ListeLocations.GetEnumerator();
}
}
}
वर्तमान नियंत्रक
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using CAD_CMDBv2.Models;
namespace CAD_CMDBv2.Areas.Locations.Controllers
{
public class LocationsController : Controller
{
private ModeleDonneesCMDBContext db = new ModeleDonneesCMDBContext();
// GET: Locations/Locations
public ActionResult Index()
{
var liste = db.Locations.ToList();
var listeTriee = liste.OrderBy(t => t.site_name);
return View(listeTriee);
}
...
लेकिन उस तर्ज पर सूचकांक दृश्य में IEnumerable के बारे में ही प्रकार के दो त्रुटियाँ पैदा करता है:
@Html.TextBoxFor(r => r.Recherche)
और
if (Model.ListeLocations.Count == 0)
मैं यह त्रुटि आई :
CS1061 Error 'IEnumerable' does not contain a definition for 'ListeLocations' and no extension method 'ListeLocations' accepting a first argument of type 'IEnumerable' could be found (are you missing a using directive or an assembly reference ?)
इसका क्या अर्थ है? मैं इसे कैसे हल करूं? मुझे अभी भी आईनेमरेबल इंटरफ़ेस को समझने में कुछ कठिनाई है।
@JeffreyC में AJAX के साथ खोज रूपों बनाने पर थोड़ा और अध्ययन करने के लिए आप सलाह कर सकते हैं। एक आइटम के बजाय एकाधिक आइटम। –
ठीक है, मैंने देखा है, मैंने आपके जैसा संशोधित किया है लेकिन हमेशा त्रुटियां :( –
@ जेफरीसी। मैं आपके मॉडल को 'आईन्यूमेरेबल' आदि से विरासत में देखता हूं, बस सुनिश्चित करें कि आपके पास एक मॉडल है जिसमें * एक संग्रह है, मॉडल नहीं कि * एक * संग्रह है। –