skip to Main Content

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?

2

Answers


  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 !

    Login or Signup to reply.
  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>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search