با سلام و ادب.
من متوجه نمی شم چرا مقدار parentId ارسال نمی شه. اگه ممکنه راهنمایی کنید.
کد صفحه Index:
@model IEnumerable<WebProject.Entity.ContactUS>
<div class="response-area">
<h2>تعداد نظرات : @ViewBag.count</h2>
@DisplayComment(Model.Where(x => x.ParentId == null))
@Html.ActionLink("Create", "Create", "ContactUS")
@helper DisplayComment(IEnumerable<WebProject.Entity.Conta ctUS> comments)
{
<ul class="media-list" style="background-color:aqua;box-shadow:rgb(0, 128, 128)10px 10px;">
@foreach (var comment in comments)
{
<li class="media" style="border:1px solid #272727;">
<div class="media-body" style="direction:rtl;text-align:right;background-color:yellowgreen;">
<ul class="sinlge-post-meta" style="background-color:palevioletred;">
<li style="list-style: none;">
<i class="fa fa-user"></i>
<span> </span>
@comment.Name
<span style="float:left;text-align:left;position:relative;font-size:12px;color:#f1f1f1;">
<i class="fa fa-clock-o"> ساعت ارسال </i>
@comment.InsertDateTime.ToShortTimeString()
<i class="fa fa-calendar"> تاریخ ارسال </i>
@comment.InsertDateTime.ToString("yyyy/MM/dd")
</span>
</li>
</ul>
<p style="text-indent: 5px;overflow:auto;">
@comment.CommentBox
</p>
@*<a href="#" id="btnReply_@comment.CommentId">پاسخ</a>*@
@Html.ActionLink("پاسخ", "Create", "ContactUS", new { parentId = @comment.Id }, new { @class = "", id = "btnReply_@comment.Id" })
</div>
@{
var childComment = Model.Where(x => x.ParentId == comment.Id).ToList();
if (childComment.Count > 0)
{
<ul>
<li class="second-media" style="background-color:greenyellow;">
@DisplayComment(childComment)
</li>
</ul>
}
}
</li>
}
</ul>
}
</div>
<script type="text/javascript">
$(document).ready(function () {
$("[id*=btnReply]").each(function () {
$(this).click(function () {
//آی دی کامنتی که دکمه پاسخ دهی آن فشرده شده است را در متغیر می ریزد
var commentid = $(this).attr("Id").match(/[\d]+$/);
$("#ParentId").val(commentid);
});
});
});
</script>
کد کنترلر مربوطه:
// GET: Menu/Create
public ActionResult Create()
{
ViewBag.contacts = _contactUsService.GetMany(t => t.ParentId == null).ToList();
return View();
}
// POST: Menu/Create
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(ContactUS contact,int? parentId)
{
if (ModelState.IsValid)
{
if (contact == null)
{
return View();
}
_contactUsService.Insert(contact);
return RedirectToAction("Index", "ContactUS");
}
return View(contact);
}
Entity:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace WebProject.Entity
{
public class ContactUS : BaseEntity<int>
{
#region ############### Ctor ################
public ContactUS()
{
InsertDateTime = DateTime.Now;
}
#endregion
#region
/// <summary>
/// آی دی جدول
/// </summary>
//*****************************************
//[Required]
////*****************************************
//public int CommentId { get; set; }
/// <summary>
/// کلید خارجی جدول
/// </summary>
//*****************************************
//*****************************************
public int? ParentId { get; set; }
/// <summary>
/// آی دی پست یا مطلبی که نظر برا آن ثبت خواهد شد
/// </summary>
public int PostId { get; set; }
/// <summary>
/// نام کاربر نظر دهنده
/// </summary>
//*****************************************
[Required]
[StringLength(maximumLength: 20)]
//*****************************************
public string Name { get; set; }
/// <summary>
/// ایمیل کاربر نظر دهنده
/// </summary>
//*****************************************
[Required]
[DataType(dataType: DataType.EmailAddress)]
//*****************************************
public string Email { get; set; }
/// <summary>
/// نظر کاربر
/// </summary>
//*****************************************
[Required]
[StringLength(maximumLength: 100)]
[DataType(dataType: DataType.MultilineText)]
//*****************************************
public string CommentBox { get; set; }
/// <summary>
/// در حال نمایش بودن یا نبودن نظر
/// </summary>
//*****************************************
//*****************************************
public bool CommentIsActive { get; set; }
/// <summary>
/// تاریخ و ساعت ثبت نظر
/// </summary>
//*****************************************
//*****************************************
public DateTime InsertDateTime { get; set; }
#endregion
#region ############ Navigation #############
#endregion
}
}