'Id not getting passed to Partial View form
Parent View:
@Html.Action("SetReview", "Review", new {sellerId = Model.SellerId})
[HttpGet]
public ActionResult SetReview(string sellerId)
{
return PartialView("_Review", new Finder.Models.Review()
{
SellerId = sellerId
});
}
This is the part where the Id is not getting passed
[HttpPost]
public ActionResult SetReview(Finder.Models.Review review)
{
var review2 = new Review()
{
PersonId = User.Identity.GetUserId(),
SellerId = review.SellerId,
Rating = review.Rating,
IsAnonymous = review.IsAnonymous,
CreatedOn = DateTime.UtcNow,
Content = review.Content,
};
DbContext.Reviews.Add(review2);
DbContext.SaveChanges();
return Json(new { status = "true", msg = "Successfully processed" });
}
No idea what's going wrong here. Shouldn't the get function pass the model to the post one, and the review.Id not get lost?
Solution 1:[1]
SellerId actually is in get method when you call get method and u see your view seller id is null bcos your not post it you need seller id in your post method just it !
Solution 2:[2]
Try the below code it will hit your post method
@using Finder.Models
@model Review
<form asp-controller="Review" asp-action="SetReview" method="post">
<div class="panel-group">
<div class="panel panel-default">
<div class="panel-body">
@Html.Action("SetReview", "Review", new {sellerId = Model.SellerId})
</div>
<div class="col-12">
<button type="submit" name="save" class="btn bg-blue"><i class="fa fa-floppy-o"></i>Save</button>
</div>
</div>
</div>
</form>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | TMFstudio |
| Solution 2 | sina_Islam |
