この問題についていくつかの例を見つけましたが、私のソフトウェアでは使用できません。どうすればよいでしょうか? また、なぜ私がこの問題を抱えているのか説明してもらえますか?
このオブジェクトにはパラメーターなしのコンストラクターが定義されていません。説明: 現在の Web 要求の実行中に未処理の例外が発生しました。エラーの詳細とコード内のどこでエラーが発生したかについては、スタック トレースを確認してください。
例外の詳細: System.MissingMethodException: このオブジェクトにパラメーターなしのコンストラクターが定義されていません。
SpotrStore.ドメイン
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using SportsStore.Entities;
namespace SportsStore.Concrete
{
public class EFDbContext : DbContext
{
public DbSet<Towar> Products { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SportsStore.Entities;
namespace SportsStore.Concrete
{
namespace SportsStore.Domain.Concrete
{
public class EFProductRepository
{
public EFDbContext context = new EFDbContext();
public IQueryable<Towar> Towar
{
get { return context.Products; }
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SportsStore.Entities;
namespace SportsStore.Concrete
{
public interface ITowarRepository
{
IQueryable<Towar> Towar { get; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;
namespace SportsStore.Entities
{
[Table("Towar")]
public class Towar
{
[Key]
public int Id_tow { get; set; }
public string Nazwa { get; set; }
public string Opis { get; set; }
public string Cena { get; set; }
public int Id_kat { get; set; }
}
}
SportStore.WebUi
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SportsStore.Concrete;
using SportsStore.WebUI.Models;
namespace SportsStore.WebUI.Controllers
{
public class DefaultController : Controller
{
public ITowarRepository repository;
public DefaultController(SportsStore.Concrete.ITowarRepository repo)
{
repository = repo;
}
public ActionResult Index()
{
SomeView ViewModel = new SomeView
{
Towar = repository.Towar
.OrderBy(p => p.Id_kat)
};
return View(ViewModel);
}
}
}
-----------------------------------------------
@model SportsStore.WebUI.Models.SomeView
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
@foreach (var item in @Model.Towar)
{
@item.Id_kat
}
---------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace SportsStore.WebUI.Models
{
public class SomeView
{
public IEnumerable<SportsStore.Entities.Towar> Towar { get; set; }
}
}