我的asp MVC應用程序在Visual Studio上運行良好。但是當在服務器上託管它時顯示運行時錯誤。錯誤是因爲模型爲空。但model => model.Service正在獲取值。MVC 4在Visual Studio上運行良好,但在iis上顯示運行時erron。 Model is null
Error
Line 86: </div>
Line 87: <div class="editor-field">
Line 88: @if (Model.ServiceIsLimitToList)
Line 89: {
Line 90:
在Visual Studio ifs工作正常,但在IIS上運行時顯示錯誤。該錯誤是因爲在iis上運行時模型爲空。
以下是代碼
型號
public class WorkOrderCreateViewModel : ViewModel
{
[Required]
[Display(Name = "Service")]
public string Service { get; set; }
[Required]
[Display(Name = "Property")]
public string Property { get; set; }
[Display(Name = "Asset Group")]
public string AssetGroup { get; set; }
public bool ServiceIsLimitToList { get; set; }
public List<PropertiesList> Properties { get; set; }
public List<AssetGroupList> AssetGroups { get; set; }
public List<ServiceList> ServiceLists { get; set; }
}
控制器
public class WorkOrderController : MobileWebControllerBase
{
public ActionResult Create()
{
try
{
this.EnsureSessionNotExpired();
var db = new DataAccess(this.GetConnectionString());
ViewModel.WorkOrderCreateViewModel viewModel = new ViewModel.WorkOrderCreateViewModel();
viewModel.ServiceIsLimitToList = int.Parse(this.GetSystemOption("WODefaults", "ServiceLimitToList", conn)) != 0;
viewModel.Properties = this.GetProperties();
viewModel.AssetGroups = this.GetAssetGroup();
viewModel.ServiceLists = this.GetServices();
return View(viewModel);
}
catch (Exception ex)
{
return HandleException(ex);
}
}
}
查看
@model WorkorderMobileMvc.ViewModel.WorkOrderCreateViewModel
@using (Html.BeginForm()) {
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<fieldset>
<p>
<strong>New WO</strong>
@Html.ActionLink("Home", "Index")
<a href="@Url.Content(" ~ />Content/Help.htm")" target="_blank">Help</a>
</p>
<div class="editor-label-dll">
@Html.LabelFor(model => model.ServiceLists)
</div>
<div class="editor-field">
@if (Model.ServiceIsLimitToList)
{
@Html.TextAreaFor(model => model.Service, new { @class = "txt", id = "Service" })
}
else
{
@Html.DropDownListFor(x => x.Service, new SelectList(Model.ServiceLists, "Services", "Services", Model.Service), "---Select Service---", new { Class = "field size3", id = "ddlService" })
@Html.ValidationMessageFor(model => model.Service)
}
</div>
<div class="editor-label-dll">
@Html.LabelFor(model => model.Property)
</div>
<div class="editor-field">
@Html.DropDownListFor(x => x.Property, new SelectList(Model.Properties, "Propertie", "Propertie", Model.Property), "---Select Property---", new { Class = "field size3", id = "ddlProperty" })
@Html.ValidationMessageFor(model => model.Property)
</div>
<div class="editor-label-dll">
@Html.LabelFor(model => model.AssetGroup)
</div>
<div class="editor-field">
@Html.DropDownListFor(x => x.AssetGroup, new SelectList(Model.AssetGroups, "AssetGroup", "AssetGroup", Model.AssetGroups), "---Select Asset Group---", new { Class = "field size3", id = "ddlAssetGroup" })
</div>
<div style="clear:left"></div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
你確定這不是打,因爲有些異常的catch塊? – Shyju
您是否驗證過這條線,就在您的線路上方工作? @ Html.LabelFor(model => model.ServiceLists) – ganders