sarah2
سه شنبه 12 اردیبهشت 1396, 02:22 صبح
سلام
میخام وقتی یک نظر برای خبر ارسال میکنم نیازی نباشه از DropDown عنوان خبر رو انتخاب کنم
مثلا در این تصویر Dropdown رو حذف کنم ولی هر نظری رو که ارسال میکنم مشخص باشه برای چه خبری هست
145119
بجای DropDwon از چی استفاده کنم؟
کد اکشن ثبت نظر:
public ActionResult Create()
{
ViewBag.PostId = new SelectList(db.Posts, "PostId", "Title");
return View();
}
//
// POST: /Comment/Create
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(Comment comment)
{
if (ModelState.IsValid)
{
db.Comments.Add(comment);
db.SaveChanges();
return RedirectToAction("Index");
}
ViewBag.PostId = new SelectList(db.Posts, "PostId", "Title", comment.PostId);
return View(comment);
}
کد ویو ثبت نظر:
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<fieldset>
<legend>Comment</legend>
<div class="editor-label">
@Html.LabelFor(model => model.PostId, "Post")
</div>
<div class="editor-field">
@Html.DropDownList("PostId", String.Empty)
@Html.ValidationMessageFor(model => model.PostId)
</div>
<br /><br /><br />
<div class="editor-label">
@Html.LabelFor(model => model.CommentBody)
</div>
<div class="editor-field">
@Html.TextAreaFor(model => model.CommentBody)
@Html.ValidationMessageFor(model => model.CommentBody)
</div>
<p>
<input type="submit" value="ارسال نظر" />
</p>
</fieldset>
}
میخام وقتی یک نظر برای خبر ارسال میکنم نیازی نباشه از DropDown عنوان خبر رو انتخاب کنم
مثلا در این تصویر Dropdown رو حذف کنم ولی هر نظری رو که ارسال میکنم مشخص باشه برای چه خبری هست
145119
بجای DropDwon از چی استفاده کنم؟
کد اکشن ثبت نظر:
public ActionResult Create()
{
ViewBag.PostId = new SelectList(db.Posts, "PostId", "Title");
return View();
}
//
// POST: /Comment/Create
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(Comment comment)
{
if (ModelState.IsValid)
{
db.Comments.Add(comment);
db.SaveChanges();
return RedirectToAction("Index");
}
ViewBag.PostId = new SelectList(db.Posts, "PostId", "Title", comment.PostId);
return View(comment);
}
کد ویو ثبت نظر:
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<fieldset>
<legend>Comment</legend>
<div class="editor-label">
@Html.LabelFor(model => model.PostId, "Post")
</div>
<div class="editor-field">
@Html.DropDownList("PostId", String.Empty)
@Html.ValidationMessageFor(model => model.PostId)
</div>
<br /><br /><br />
<div class="editor-label">
@Html.LabelFor(model => model.CommentBody)
</div>
<div class="editor-field">
@Html.TextAreaFor(model => model.CommentBody)
@Html.ValidationMessageFor(model => model.CommentBody)
</div>
<p>
<input type="submit" value="ارسال نظر" />
</p>
</fieldset>
}