0
空引用我有這個GET四處張貼視圖模型
public ActionResult Add(int productId, int categoryId, int styleId)
{
...
和這個職位:
[HttpPost]
public ActionResult Add(OrderDetailsViewModel thisWindowModel)
{
if (!ModelState.IsValid)
{
return View(thisWindowModel);
}
在我看來,即時得到一個空引用異常的位置:
<h2>Order Details:@Model.StyleName</h2>
即使雖然我有這個看法
@Html.HiddenFor(x=>x.StyleName)
我已經調試過它,可以看到這是一個字符串預期。
,當我從我的觀點IM仍然得到一個空引用異常徹底清除線....
任何想法?它對我沒有意義!
感謝
更新:
Get方法是:
public ActionResult Add(int productId, int categoryId, int styleId)
{
AccountInfo objAccData = new AccountInfo();
AccountData thisAccInfo = objAccData.GetInfo("ABC");//TempData["FakeAccNo"].ToString());
CheckSupplier objCheckFrameSupp = new CheckSupplier(styleId, thisAccInfo.DepNo);
int FrameSupp = objCheckFrameSupp.GetFrameSupplier();
WindowColoursFromStyle objColItems = new WindowColoursFromStyle(styleId);
WindowsOptionsFromStyleSupplier objStyleOps = new WindowsOptionsFromStyleSupplier(styleId, FrameSupp, categoryId);
var repo = new ProductsRepository();
var style = repo.GetStyle(styleId);
var productCategory = repo.GetProductsCategory(categoryId);
var product = repo.GetProduct(productId);
var salesOrderId = SessionData.SalesOrderId;
return View(new OrderDetailsViewModel(salesOrderId, "Add")
{
StyleName = style.Name,
MinimumHeight = style.Minimum_Height,
MinimumWidth = style.Minimum_Width,
MaximumWidth = style.Maximum_Width,
MaximumHeight = style.Maximum_Height,
External_Image_Path = style.External_Image_Path,
Category = productCategory,
Product = product,
InternalColours = objColItems.InternalColours,
ExternalColours = objColItems.ExternalColours,
CillOptions = objStyleOps.CillOptions,
AddOnBottomOptions = objStyleOps.AddOnsOptions,
AddOnTopOptions = objStyleOps.AddOnsOptions,
AddOnLeftOptions = objStyleOps.AddOnsOptions,
AddOnRightOptions = objStyleOps.AddOnsOptions,
NoTransoms = objStyleOps.NoTransoms,
NoDummyTransoms = objStyleOps.NoDummyTransoms,
NoMullions = objStyleOps.NoMullions,
NoDummyMullions = objStyleOps.NoDummyMullions,
GlassUnits = objStyleOps.GlassUnits,
GlassTypes = objStyleOps.GlassOptions,
HasOpener = objStyleOps.HasOpeners,
Handles = objStyleOps.HandleOptions,
Lock = objStyleOps.LockOptions,
Stay = objStyleOps.StayOptions,
FrameThicknessBottom = objStyleOps.FrameThicknessOptions,
FrameThicknessTop = objStyleOps.FrameThicknessOptions,
FrameThicknessLeft = objStyleOps.FrameThicknessOptions,
FrameThicknessRight = objStyleOps.FrameThicknessOptions,
MullionThickness = objStyleOps.MullionThicknessOptions,
TransomThickness = objStyleOps.TransomThinknessOptions,
SashThinkness = objStyleOps.SashThinknessOptions,
FrameVent = objStyleOps.VentOptions,
SashVent = objStyleOps.VentOptions,
WindowStyleID = styleId,
AccountNumber ="BTCA",// TempData["FakeAccNo"].ToString(),
DepotNumber = thisAccInfo.DepNo,
FrameSupplier = FrameSupp,
FrameNumber = 1,// (int)TempData["FrameNumber"],
DripBars = objStyleOps.DripBarOptions,
DrainageOptions = objStyleOps.DrainageOptions,
RestrictorOptions = objStyleOps.RestrictorOptions,
ReinforcingTypes = objStyleOps.ReinforcingTypes,
ReinforcingRules = objStyleOps.ReinforcingRules,
IsDoor = objStyleOps.isDoor,
KickPlateOptions = objStyleOps.KickPlateOptions
});
}
視圖頂部的幾行是esentially ....
@model ViewModel.OrderDetailsViewModel
<div class="row heading-row">
<div class="col-md-8">
@*<h2>Order Details:@(Model.StyleName)</h2>*@
</div>
</div>
@Html.Partial("_OrderDetailsForm",Model)
這與基本上選擇/下拉菜單的負載,
局部視圖形式爲開始:
@model ViewModel.OrderDetailsViewModel
@using (Html.BeginForm(Model.FormType, "Products", FormMethod.Post, new { @class = "form-horizontal" }))
{
請添加'OrderDetailsViewModel'的代碼。也是你的全部行動和觀點。 –
如何使用「int productId,int categoryId,int styleId」,參數?獲取方法的分享返回部分,請 –
您如何在視圖中定義模型?發佈您的視圖的開始(頂部)幾行,並將其名稱文件 – Satpal