在查看详细页面中添加评论部分
我正在开发 Bookevent 应用程序,我想在 eventdetail 页面上添加评论部分,我已经在使用 EventViewModel 来显示事件详细信息,并且我还添加了评论部分,以便用户可以发布评论。 所以基本上,我的问题是如何在同一视图页面上使用评论模型。我搜索了一下,发现我们可以使用tuple。但我认为在这种情况下这不是一个好的做法。有人可以建议任何其他方式吗?
CommentViewModel.cs
public class CommentViewModel
{
[Required]
public string CommentAdded { get; set; }
[Required]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public DateTime Date { get; set; }
[Required]
public int EventId { get; set; }
}
EventDetail.cshtml
@model EventViewModel
<div class="container">
<div class="row">
<h2 class="mt-5 mb-5 text-center">Event Details</h2>
<div class="table-responsive field ms-5 mt-3">
<table class="table" id="stu_table">
<tbody>
<tr>
<th>Title</th>
<td>Title</td>
</tr>
<tr>
<th>Date</th>
<td>Date</td>
s
</tr>
<tr>
<th>Location</th>
<td>Location</td>
</tr>
<tr>
<th>StartTime</th>
<td>StartTime</td>
</tr>
<tr>
<th>Type</th>
<td>Type</td>
</tr>
<tr>
<th>Duration</th>
<td>Duration</td>
</tr>
<tr>
<th>Description</th>
<td>Description</td>
</tr>
<tr>
<th>OtherDetails</th>
<td>OtherDetails</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="row">
<form asp-controller="Comment" asp-action="CreateComment">
<div>
<label asp-for="CommentAdded"class="control-label">Add Comment</label>
<textarea asp-for="CommentAdded"rows="4" cols="50"></textarea>
<input class="btn-btn-default" value="Create" type="submit"/>
</div>
</form>
</div>
</div>
I am working on Bookevent application I want to add comment section on eventdetail page where I am already using EventViewModel to display information of event detail and I also what to add comment section so user can post the comment.
So basically, My question is how can I use comment model as well on same view page. I searched for it and I found that we can use tuple. But I think that's not good practice in this case. Can Someone suggest any other way please.
CommentViewModel.cs
public class CommentViewModel
{
[Required]
public string CommentAdded { get; set; }
[Required]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public DateTime Date { get; set; }
[Required]
public int EventId { get; set; }
}
EventDetail.cshtml
@model EventViewModel
<div class="container">
<div class="row">
<h2 class="mt-5 mb-5 text-center">Event Details</h2>
<div class="table-responsive field ms-5 mt-3">
<table class="table" id="stu_table">
<tbody>
<tr>
<th>Title</th>
<td>Title</td>
</tr>
<tr>
<th>Date</th>
<td>Date</td>
s
</tr>
<tr>
<th>Location</th>
<td>Location</td>
</tr>
<tr>
<th>StartTime</th>
<td>StartTime</td>
</tr>
<tr>
<th>Type</th>
<td>Type</td>
</tr>
<tr>
<th>Duration</th>
<td>Duration</td>
</tr>
<tr>
<th>Description</th>
<td>Description</td>
</tr>
<tr>
<th>OtherDetails</th>
<td>OtherDetails</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="row">
<form asp-controller="Comment" asp-action="CreateComment">
<div>
<label asp-for="CommentAdded"class="control-label">Add Comment</label>
<textarea asp-for="CommentAdded"rows="4" cols="50"></textarea>
<input class="btn-btn-default" value="Create" type="submit"/>
</div>
</form>
</div>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“我想在EventDetail页面上添加评论部分,我已经在使用EventViewModel”,“
好的,您有2个选项。
在这种情况下,尽管您不能使用“ asp-for =” 从ViewBag/viewData []中获得的东西。
如果要在提交表单后将数据发送回控制器,请使用“ name =” ,并在控制器操作中使用相同的字符串名称进行参数。
您的代码看起来像这样:
"I want to add comment section on eventdetail page where I am already using EventViewModel"
Okay, so you have 2 options.
In this case though you can't use "asp-for=" for the things you got from the ViewBag/ViewData[].
If you want to send the data back to the controller after submitting the form, use "name=" and make a parameter in your controller action with the same string name.
Your code will look like this: