Home > OS >  Id not getting passed to Partial View form
Id not getting passed to Partial View form

Time:04-13

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?

CodePudding user response:

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 !

CodePudding user response:

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 >
            <div >
                <div >
                  @Html.Action("SetReview", "Review", new {sellerId = Model.SellerId})
               </div>
               <div >
               <button type="submit" name="save" ><i ></i>Save</button>
               </div>
            </div>
        </div>
    </form>
  • Related