نوشته شده توسط
ژیار رحیمی
public class City
{
public int CityId { get; set; }
public string Name { get; set; }
public int CityTypeId { get; set; }
[ForeignKey(nameof(CityTypeId))]
public virtual CityType CityType { get; set; }
public int? ParentId { get; set; }
[ForeignKey(nameof(ParentId))]
public virtual City Parent { get; set; }
}
سلام
من صفحه زیر را صراحی کردم
@model WebApplication2.Models.City
@{
ViewBag.Title = "Create";
}
<h2>Create</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>City</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.CityTypeId, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.CityTypeId, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.CityTypeId, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.ParentId, "ParentId", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("ParentId", null, htmlAttributes: new {@class = "form-control"})
@Html.ValidationMessageFor(model => model.ParentId, "", new {@class = "text-danger"})
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
اما مشکلی که دارم
بار اول مثلا می نویسم ایران درست ثبت می شود و ParentId هم null ثبت میشود
اما برای بار دیگر می خواهم یک کشور دیگر ثبت کنم ParentId را ایران نشان می دهد درصورتیکه من می خواهم بتوانم یک کشور دیگر ثبت کنم که ParentId انهم null باشد
باید چکار کنم
باتشکر