C# 如何";书;并显示其他用户';s仅针对在MVC中单击按钮或ActionLink的用户在另一个视图中发布?
这是型号C# 如何";书;并显示其他用户';s仅针对在MVC中单击按钮或ActionLink的用户在另一个视图中发布?,c#,button,model-view-controller,click,actionlink,C#,Button,Model View Controller,Click,Actionlink,这是型号UserPosts.cs: public int Id { get; set; } public string Destination { get; set; } public DateTime DepartureDate { get; set; } public string Meetplace { get; set; } public byte NumberofSeats { get; set; } public virtual ApplicationUser User { get;
UserPosts.cs
:
public int Id { get; set; }
public string Destination { get; set; }
public DateTime DepartureDate { get; set; }
public string Meetplace { get; set; }
public byte NumberofSeats { get; set; }
public virtual ApplicationUser User { get; set; }
public string UserId { get; set; }
这是控制器中的创建方法:
public ActionResult Create()
{
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(UserPosts userposts)
{
var userId = User.Identity.GetUserId();
if (ModelState.IsValid)
{
userposts.UserId = userId;
_db.UserPosts.Add(userposts);
_db.SaveChanges();
return RedirectToAction("Index","UserPosts");
}
return View(userposts);
}
这是索引视图:
@model IEnumerable<Carpool.Models.UserPosts>
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>All posts</h2>
<div class="allposts">
@foreach (var m in Model)
{
<div class="posts">
<table class="table">
<tr>
<td><b>Destination</b></td>
<td>@m.Destination</td>
</tr>
<tr>
<td><b>Departure Date</b></td>
<td>@m.DepartureDate</td>
</tr>
<tr>
<td><b>Meetplace</b></td>
<td>@m.Meetplace</td>
</tr>
<tr>
<td><b>Number of Seats</b></td>
<td>@m.NumberofSeats</td>
</tr>
<tr>
<td>
------>Here I want to add an actionlink/button<------
}
</td>
</tr>
</table>
</div>
<br /><br />
}
</div>
@model IEnumerable
@{
ViewBag.Title=“Index”;
Layout=“~/Views/Shared/_Layout.cshtml”;
}
所有职位
@foreach(模型中的var m)
{
目的地
@m、 目的地
离港日
@m、 出发日期
会场
@m、 会场
座位数
@m、 座位数
------>这里我想添加一个actionlink/按钮