私はASP.NET Core MVCプロジェクト(v.1.0.0)を作成しています。現在、ステージング環境と本番環境に公開されています。モデルクラスの1つが最近更新され、2つの新しいプロパティが追加されました。ASP.NET Core MVC Viewsレポートモデルクラスに新しいプロパティの定義がありません
開発環境とステージング環境の両方で、これらの新しいプロパティは正常に動作しています。
ただし、運用環境に展開すると、これらの新しいプロパティを参照するビューは、クラスに定義されていないことを報告します。プロダクション内:
1)Entity Frameworkは、更新されたクラスに基づいて、移行を正常に実装し、データベーススキーマを更新することができました。
2)コントローラは、これらの新しいプロパティと対話したり、データベースに保存したりすることもできます。
3)ただし、同じクラスに対して厳密に型指定されたビューを使用すると、LocationにLatitudeの定義が含まれていないことを示すエラーがスローされます。
また、同じビューは、開発環境とステージング環境の新しいプロパティでうまく動作します。
Location.cs
public class Location
{
public int Id { get; set; }
[Required]
public string Name { get; set; }
[Required]
[Display(Name = "Address Line 1")]
public string AddressLine1 { get; set; }
[Display(Name = "Address Line 2")]
public string AddressLine2 { get; set; }
[Required]
public string City { get; set; }
[Required]
public string State { get; set; }
[Required]
[Display(Name = "Postal Code")]
public int PostalCode { get; set; }
public double Latitude { get; set; } // New
public double Longitude { get; set; } // New
public string Notes { get; set; }
public Boolean IsActive { get; set; }
public Boolean IsDeleted { get; set; }
}
AddLocation.cshtml
私はフィールドが隠され、0にデフォルト設定されている理由である外部APIから提出上の緯度と経度を取得するには、コントローラを使用していますAddLocationビューに追加します。値を更新または表示するために使用される他のビューでも、同じエラーがスローされます。
@model MyMvcApp.Models.Location
@{
ViewData["Title"] = "Add Location";
}
<form asp-action="AddLocation">
<div class="form-horizontal">
<hr />
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<input type="hidden" asp-for="Latitude" value="0" />
<input type="hidden" asp-for="Longitude" value="0" />
<div class="form-group">
<label asp-for="Name" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input asp-for="Name" class="form-control" />
<span asp-validation-for="Name" class="text-danger" />
</div>
</div>
<div class="form-group">
<label asp-for="AddressLine1" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input asp-for="AddressLine1" class="form-control" />
<span asp-validation-for="AddressLine1" class="text-danger" />
</div>
</div>
<div class="form-group">
<label asp-for="AddressLine2" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input asp-for="AddressLine2" class="form-control" />
<span asp-validation-for="AddressLine2" class="text-danger" />
</div>
</div>
<div class="form-group">
<label asp-for="City" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input asp-for="City" class="form-control" />
<span asp-validation-for="City" class="text-danger" />
</div>
</div>
<div class="form-group">
<label asp-for="State" class="col-md-2 control-label"></label>
<div class="col-md-10">
<select asp-for="State" asp-items="@ViewBag.StateList" class="form-control"></select>
<span asp-validation-for="State" class="text-danger" />
</div>
</div>
<div class="form-group">
<label asp-for="PostalCode" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input asp-for="PostalCode" class="form-control" />
<span asp-validation-for="PostalCode" class="text-danger" />
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<div class="checkbox">
<input asp-for="IsActive" />
<label asp-for="IsActive"></label>
</div>
</div>
</div>
<div class="form-group">
<label asp-for="Notes" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input asp-for="Notes" class="form-control" />
<span asp-validation-for="Notes" class="text-danger" />
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Add" class="btn btn-default" />
</div>
</div>
</div>
</form>
@section Scripts {
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}
新しいプロパティへの参照を削除またはコメントアウトすると、ビューがうまく表示されます。
どのように私はこれを修正することができます任意のアイデア?
モデルクラスは、他のライブラリまたはコントローラとビューと同じWebプロジェクトにありますか? – dotnetstep
コントローラとビューの両方と同じプロジェクトにあります。 –
新しいdllが正常にビルドされ、運用環境に正しく展開されていることを確認してください。 – dotnetstep