2016-08-05 5 views
0

エラー:@html部分的なエラー、MVC

CS1973: 'System.Web.Mvc.HtmlHelper' has no applicable method named 'Partial' but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax.

この問題をソートする方法をわかりません。 モデル:

namespace MVCRecsStarter.ViewModels{ public class AdminViewModel 
{ 
    public Category category { get; set; } 
    public IEnumerable<Rec> recs { get; set; } 
    public IEnumerable<Category> categoriesrecs { get; set; } 
}} 

ビュー:

<div id='leftItemTemplate'> 
    @Html.Partial("admin", Model.category) 
</div> 

<div id='rightItemTemplate'> 
    <h3>Find Rec to Update</h3> 
    @Html.Partial("_select_recs", Model.recs) 
    @if (Model.categoriesrecs != null) 
    { 
     @Html.Partial("_select_categories", Model.categoriesrecs) 
    } 
</div> 

_select_category:

@using (Html.BeginForm()){ 
@Html.AntiForgeryToken() 

<div class="form-horizontal"> 
    <h4>Rec</h4> 
    <hr /> 
    @Html.ValidationSummary(true, "", new { @class = "text-danger" }) 
    <div class="form-group"> 
     @Html.LabelFor(model => model.RecTitle, htmlAttributes: new { @class = "control-label col-md-2" }) 
     <div class="col-md-10"> 
      @Html.EditorFor(model => model.RecTitle, new { htmlAttributes = new { @class = "form-control" } }) 
      @Html.ValidationMessageFor(model => model.RecTitle, "", new { @class = "text-danger" }) 
     </div> 
    </div> 

    <div class="form-group"> 
     @Html.LabelFor(model => model.RecURL, htmlAttributes: new { @class = "control-label col-md-2" }) 
     <div class="col-md-10"> 
      @Html.EditorFor(model => model.RecURL, new { htmlAttributes = new { @class = "form-control" } }) 
      @Html.ValidationMessageFor(model => model.RecURL, "", new { @class = "text-danger" }) 
     </div> 
    </div> 

    <div class="form-group"> 
     @Html.LabelFor(model => model.RecDescription, htmlAttributes: new { @class = "control-label col-md-2" }) 
     <div class="col-md-10"> 
      @Html.EditorFor(model => model.RecDescription, new { htmlAttributes = new { @class = "form-control" } }) 
      @Html.ValidationMessageFor(model => model.RecDescription, "", new { @class = "text-danger" }) 
     </div> 
    </div> 

    <div class="form-group"> 
     @Html.LabelFor(model => model.Image, htmlAttributes: new { @class = "control-label col-md-2" }) 
     <div class="col-md-10"> 
      @Html.EditorFor(model => model.Image, new { htmlAttributes = new { @class = "form-control" } }) 
      @Html.ValidationMessageFor(model => model.Image, "", new { @class = "text-danger" }) 
     </div> 
    </div> 

    <div class="form-group"> 
     @Html.LabelFor(model => model.Category, htmlAttributes: new { @class = "control-label col-md-2" }) 
     <div class="col-md-10"> 
      @Html.EditorFor(model => model.Category, new { htmlAttributes = new { @class = "form-control" } }) 
      @Html.ValidationMessageFor(model => model.Category, "", new { @class = "text-danger" }) 
     </div> 
    </div> 

    <div class="form-group"> 
     <div class="col-md-offset-2 col-md-10"> 
      <input type="submit" name="action" value="Create" /> 
      <input type="submit" name="action" value="Edit" /> 
     </div> 
    </div> 
</div>} 

_select_rec:

<div> 
@using (Html.BeginForm("SelectRec", "Categories", FormMethod.Post)) 
{ 
    <div> 
     <p> 
      <select name="recs"> 
       @foreach (var item in Model) 
       { 
        <option value="@item.rec">@item.rec</option> 
       } 
      </select> 
     </p> 
     <p> 
      <input type="submit" name="action" 
        value="Select Rec" /> 
     </p> 
    </div> 
} 

コントローラー:

public ActionResult Admin() 
    { 
     Category category = new Category(); 
     IEnumerable<Rec> recs = repository.GetAllRecs(); 

     AdminViewModel adminViewModel = new AdminViewModel(); 
     adminViewModel.category = category; 
     adminViewModel.recs = recs; 

     return View(adminViewModel); 
    } 

Model.Rec

namespace MVCRecsStarter.Models{ 
public class Rec 
{ 
    [Key, Display(Name = "ID")] 
    [ScaffoldColumn(false)] 
    public int RecId { get; set; } 
    [Required, StringLength(100), Display(Name = "Title")] 
    public string RecTitle { get; set; } 
    Required, StringLength(150), Display(Name = "Link")] 
    public string RecURL { get; set; } 

    [StringLength(1000), Display(Name = "Description")] 
    public string RecDescription { get; set; } 

    [StringLength(150), Display(Name = "Image")] 
    public string Image { get; set; } 

    [Required, StringLength(15)] 
    public string Category { get; set; } 

    public virtual ICollection<Comment> Comments { get; set; } 
}} 

任意のアイデア?

+0

これが有効であるあなたは確か?メンバーではなく、リスト(コレクション)に見えますか? (REC)Mod​​el.recs – Nikki9696

+0

@ Html.Partial( "_ select_recs"、(IEnumerable ))Model.recsを試してみて、コレクションである他のものと同じ – Nikki9696

+0

エラーが出なかった:CS0246:型または名前空間名前 'Rec'が見つかりませんでした – II2710

答えて

0

さて、あなたが何をしているのか分かっていれば、これは私のために働いています。カテゴリにバインドするための別のページがあることに注意してください。

enter image description hereenter image description here

AdminController

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.Mvc; 
using WebApplication2.Models; 

namespace WebApplication2.Controllers 
{ 
    public class AdminController : Controller 
    { 
     // GET: Admin 
     public ActionResult Admin() 
     { 
      Category category = new Category() { Name = "TestC" }; 
      List<Rec> rc = new List<Rec>() 
      { 
       new Rec() { RecId=1, RecTitle="Test" } 
      }; 

      AdminViewModel adminViewModel = new AdminViewModel(); 
      adminViewModel.category = category; 
      adminViewModel.recs = (IEnumerable<Rec>)rc; 

      return View(adminViewModel); 
     } 
    } 
} 

Admin.cshtml

@model WebApplication2.Models.AdminViewModel 
    <div style="height:50px"></div> 
<div id='leftItemTemplate' style="float:left;width:30%;border:1px solid black;"> 
    <p>Category div</p> 
    @Html.Partial("adminCategory", Model.category) 
</div> 

<div id='rightItemTemplate' style="float:right;width:70%;border:1px solid black;"> 
    <p>Rec div</p> 
    <h3>Find Rec to Update</h3> 
    @Html.Partial("_select_recs", Model.recs) 
    @if (Model.categoriesrecs != null) 
    { 
     @Html.Partial("_select_categories", Model.categoriesrecs) 
    } 
</div> 

_select_recs

@model IEnumerable<WebApplication2.Models.Rec> 

<h2>_select_recs</h2> 
<ul> 
    @foreach (var item in Model) 
    { 
     <li>@item.RecTitle</li> 
    } 
</ul> 

AdminCategoryビュー

@model WebApplication2.Models.Category 
<h3>Category details here</h3> 
<p><b>@Model.Name</b></p> 
+0

悪い明日を続け、あなたに戻って、あなたの助けに感謝します。 – II2710

関連する問題