请先阅读:)谢谢:)
我有一个称为RMA(http://localhost/User/RMA?Id=132)的视图,它显示了有关产品的一些详细信息,还显示了注释(列表),其中与该产品相关,并且也有可能在同一视图中更新每个评论,但是首先我应该通过id获取评论,然后我可以在同一视图中更新每个评论,但是我确实存在一些问题,无法通过id在同一视图中,我也在其中显示评论列表。让我描述问题:)
控制器:
public ActionResult CommentsId(int? ComID, int? id)
{
//Show Comment per ID
var querythree = (from RH in db.RMA_History
join RB in db.Besked on RH.Id equals RB.RMAID
where RB.ID == ComID && RB.RMAID == id
select new VMRMA
{
RBID = RB.ID,
RBPM = RB.MSG,
RBRMAID = RB.RMAID
});
var q = querythree.FirstOrDefault();
return View(q);
}
查看(CommentsId.cshtml):
@using ModelNameSpace.Models
@model VMRMA
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>CommentsById</title>
</head>
<body>
<div>
<input type="hidden" name="ComID" value="@Model.RBID" />
<input type="hidden" name="RMAID" value="@Model.RBRMAID" />
<p>@Model.RBPM</p>
</div>
</body>
</html>
为RMA的视图,用户单击更新链接:
@using NameSpace.Models
@model VMRMA
//Loop Comments
@foreach (var item in Model.Comment_Lists)
{
<h3 class="h5">@item.PM</h3>
//Link
<a href="/User/CommentsId?ComID=@item.ID&id=@item.RMAID">Update</a>
}
控制器:
public ActionResult _CommentsById(int? ComID , int? id)
{
var querythree = (from RH in db.RMA_History
join RB in db.Besked on RH.Id equals RB.RMAID
where RB.ID == ComID && RB.RMAID == id
select new VMRMA
{
RBID =RB.ID,
RBPM =RB.MSG,
RBRMAID=RB.RMAID
});
var q = querythree.FirstOrDefault();
return PartialView("_CommentsById", q);
}
PartialView(_CommentsById.cshtml):
@using ModelNameSpace.Models
@model VMRMA
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>CommentsById</title>
</head>
<body>
<div>
<input type="hidden" name="ComID" value="@Model.RBID" />
<input type="hidden" name="RMAID" value="@Model.RBRMAID" />
<p>@Model.RBPM</p>
</div>
</body>
</html>
View RMA,在其中渲染PartialView:
@using NameSpace.Models
@model VMRMA
//Select From Parent Model HRMAS
<input type="text" class="form-control disabled" value="@Model.HRMAs.FirmaNavn">
//Loop Comments list
@foreach (var item in Model.Comment_Lists)
{
<h3 class="h5">@item.PM</h3>
//Link
<a data-toggle="modal" data-target="#myModal" href="/User/_CommentsById?ComID=@item.ID&id=@item.RMAID">Update</a>
}
<div class="container">
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content--
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4></div>
<div class="modal-body">
@Html.Partial("_CommentsById")
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
RMA控制器:
public ActionResult RMA(int? id, VMRMA model)
{
//List comments
var queryTwo = (from RH in db.RMA_History
join RB in db.Besked on RH.Id equals RB.RMAID
where RB.RMAID == id
select new VMRMA.Comment_List
{
//Select Something
});
var query = (from RH in db.RMA_History
join RS in db.RMAStatus on RH.StatusID equals RS.ID
where RH.Id == id
select new VMRMA.HRMA
{
//Select Something
});
model.HRMAs = query.FirstOrDefault();
model.Comment_Lists = queryTwo.ToList();
return View(model);
}
ViewModel VMRMA:
public class VMRMA
{
public int? RBID { get; set; }
public string RBPM { get; set; }
public int? RBRMAID { get; set; }
public Comment_PM Comment_PMs { get; set; }
public class Comment_PM
{
public Comment_PM()
{
}
public Comment_PM(string PM, int? ID, DateTime Date, string Forfatter, string whos, int? RMAID)
{
this.PM = PM;
this.ID = ID;
this.Date = Date;
this.Forfatter = Forfatter;
this.whos = whos;
this.RMAID = RMAID;
}
public int? ID { get; set; }
public string PM { get; set; }
public DateTime Date { get; set; }
public string Forfatter { get; set; }
public string whos { get; set; }
public int? RMAID { get; set; }
}
------------------------------
public HRMA HRMAs { get; set; }
public class HRMA
{
public HRMA(string FirmaNavn)
{
this.FirmaNavn = FirmaNavn;
}
public string FirmaNavn{ get; set; }
}
------------------------------
public List<Comment_List> Comment_Lists { get; set; }
public class Comment_List
{
public Comment_List()
{
}
public Comment_List(string PM, int? ID, DateTime Date, string Forfatter , string whos , int? RMAID)
{
this.PM = PM;
this.ID = ID;
this.Date = Date;
this.Forfatter = Forfatter;
this.whos = whos;
this.RMAID = RMAID;
}
public int? ID { get; set; }
public string PM { get; set; }
public DateTime Date { get; set; }
public string Forfatter { get; set; }
public string whos { get; set; }
public int? RMAID { get; set; }
}
}