나는 몇 시간 동안이 작업을 수행하려고 노력했습니다. 모델이라는 두 개의 모델에 Model이라는 모델이 있는데, 모델에서 데이터를 가져 오려고합니다. 뷰에 표시 할 모델, 하나의 모델 문만 뷰에 적용 할 수 있다는 것을 알고 있습니다. 그래서 내가보기에서 참조하고 싶습니다 속성을 포함하는 ViewModels을 만들었습니다. 지금은 컴파일을 받고 메신저를 실행할 때 오류 :은 ASP.NET 내부에 두 개의 모델 속성을 추가하는 방법입니다.
"컴파일러 오류 메시지 : CS0246 : 형식 또는 네임 스페이스 이름 '모델'을 찾을 수 없습니다 (사용 지시문이나 어셈블리 참조가 누락 되었습니까?) "
내가 할 수있는 다른 방법이 있다면 조언 해 주시면 감사하겠습니다.
새로운 뷰 모델 내 내부보기
public class MainModelscs <T> where T :class
{
public StoreAudit StoreAudit { get; set; }
public StoreQuestions StoreQuestions { get; set; }
public List<string> StoreWindow { get; set; }
public IPagedList<T> IndexList { get; set; }
}
뷰 모드의 특성,
@model PopMarketing.ViewModel.MainModelscs<PopMarketing.Models>
모델 1
public class StoreQuestions
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Key]
public int ReviewId { get; set; }
public int AuditId { get; set; }
public int QuestionOne { get; set; }
public string QuestionTwo { get; set; }
public string QuestionThree { get; set; }
public string QuestionFour { get; set; }
}
을 생성
모델 2
[Key]
[Column(Order = 1)]
public int AuditId { get; set; }
public string Date { get; set; }
public int StoreNumber { get; set; }
public string StoreName { get; set; }
public string Address { get; set; }
public string Manager { get; set; }
컨트롤러 방법
public class AuditController : Controller
{
private PopMarketingContext db = new PopMarketingContext();
//
// GET: /Audit/
private const string PASSWORD = "MarchJava2016";
public ActionResult Index(string searchString)
{
int number;
int check;
bool result = Int32.TryParse(searchString, out number);
if (result)
{
check = Convert.ToInt32(searchString);
var shops = from s in db.StoreAudit
select s;
if (!String.IsNullOrEmpty(searchString))
{
shops = shops.Where(s => s.StoreName.ToUpper().Contains(searchString.ToUpper()) ||
s.StoreNumber.Equals(check));
}
return View(shops.ToList());
}
else
{
var shops = from s in db.StoreAudit
select s;
if (!String.IsNullOrEmpty(searchString))
{
shops = shops.Where(s => s.StoreName.ToUpper().Contains(searchString.ToUpper()));
}
return View(shops.ToList());
}
}
컨트롤러와 뷰 모델에서 (부분적으로) 결합하려는 두 모델을 보여줄 수 있습니까? – Devilscomrade
whta는 PopMarketing.Models이고 Models의 전체 네임 스페이스는 무엇입니까? – Nirman
PopMarketing.Models를 전달해야합니다.에서 @model PopMarketing.ViewModel.MainModelscs –