나는 많은 것을 수색했다. 아마도 잘못된 곳을 찾고 있습니다 ...통화 구성보기 구성 요소에서 실패 - 해결 방법?
제품리스트에 비용이 있습니다. 해당 모델에서 추출한 :
[Display(Name = "Cost Price")]
[DataType(DataType.Currency)]
public decimal CostPrice { get; set; }
이 수준에서 데이터 형식을 사용하고 있는데 제대로 작동합니다.
그런 다음 제품 모델을 Kitset 모델에서 참조하십시오. 완벽한 솔루션을 생산하는 제품 모음집입니다. 실제 예는 타이어, 휠, 휠 너트 및 허브 캡 일 수 있습니다.
public class QuoteToKitset
{
public int QuoteToKitsetID { get; set; }
public int QuoteID { get; set; }
public int ProductKitsetID { get; set; }
public Quote Quote { get; set; }
public ProductKitset ProductKitset { get; set; }
}
나는 다음 ViewComponent이이 체인의 끝에 :
public class ProductKitset
{
public int ProductKitsetID { get; set; }
[Display(Name ="Kitset Name")]
public int ProductKitsetNameID { get; set; }
public decimal Quantity { get; set; }
[Display(Name = "Product")]
public int ProductID { get; set; }
public Product Product { get; set; }
public ProductKitsetName ProductKitsetName { get; set; }
}
그런 다음 어떤 사람들은 따옴표를 원하는대로, 따옴표는 하나 이상의 Kitset을 포함 할 수있다, 나는 세 번째 모델 QuoteToKitset 있습니다. ViewComponent는 견적 내 kitset에 포함 된 제품 목록을 반환합니다. 목적은 인용문을 작성하는 사람이 다른 항목을 추가해야하는 경우 키 시트에있는 내용을 볼 수 있도록하기 위함입니다. 휠 예제로 되돌아 가면 아마도 디스크 브레이크 로터가 필요할 것입니다.
이 작업은 정상적으로 작동하며 원하는 결과를 반환합니다. viewComponent 완성도를 들어 :
public class ProductKitsetsViewComponent : ViewComponent
{
private readonly Eva804Context _context;
public ProductKitsetsViewComponent(Eva804Context context)
{
_context = context;
}
public IViewComponentResult Invoke(int id)
{
var productKitset = from p in _context.ProductKitset
.Include(p=>p.Product)
.Where(p => p.ProductKitsetNameID == id)
select p;
return View(productKitset);
}
}
그런 다음 ViewComponent의 기본보기에 내가 가진 : 내가 말했듯이 제대로 작동
@foreach (var p in Model)
{
<tr>
<td>
@p.Product.ProductCode
</td>
<td>
@p.Quantity
</td>
<td>
@p.Product.ProductDescription.Substring(0, Math.Min(p.Product.ProductDescription.Length, 38))
</td>
<td>
@p.Product.CostPrice
</td>
. 원가에 대한 서식 지정을 제외하고. 이 글을 읽었을 때, 여전히 복잡한 세상으로 나아가는 길을 배우고 있는데, Cost Price 포맷팅은 제품 모델의 DataType에 의해 설정됩니다.
현실 세계에서는 형식이 ViewComponent에서 재현되지 않습니다.
데이터 유형이 무시되는 이유는 무엇입니까? 어떻게 해결할 수 있습니까? 무언가가 여기서 어떻게 작동하지 않았는지 생각하는 데 잘못된 것이 있습니까?
어떤 형식입니까? 출력은 무엇입니까? –
죄송합니다.이 댓글을 확인하지 못했습니다. 나는 형식을 적용하지 않고 단순히 10 진수 형식을 얻고 있습니다. 왜 이런 일이 일어나고 있는지 확실하지 않지만 아래에서는 해결했습니다. – BitLost