0

This project got some review that user can read and rate. View Details are displaying a specific review, and I'm using rating in same view.

Rating(non-partial) / _RatingPartial - (both view have same code)

@model xxxx.ViewModel.RateReviewVm

<h6>Rate the review</h6>

@using (Html.BeginForm()) {
    <div class="form-group">
        @Html.LabelFor(m => m.SelectedRating)
        @Html.DropDownListFor(m => m.SelectedRating, Model.RatingList, "Rate the review", new { @class = "form-control" })
        @Html.ValidationMessageFor(m => m.SelectedRating)
    </div>

    <button type="submit" class="btn btn-default submit">Rate</button>
}

The non-partial were simply called by @Html.Action("Rating", new { id = Model.Id }) inside Details(about review) View. Works fine, but the problem is it somehow generate a footer which I can't get rid off.

Is there any way to remove the footer without re-write it into partial-view? I tried to make partial view work, but then it wouldn't work anymore and I get errors by doing:

inside Details (Partial attempt)

@{
    var newRating = new xxxx.ViewModel.RateReviewVm { ReviewId = Model.Id };

    Html.RenderPartial("_RatingPartial", newRating);

}

The ViewData item that has the key 'SelectedRating' is of type 'System.Int32' but must be of type 'IEnumerable'.

If I change SelectedRating from int to IEnumerable<SelectListItem> I get following error:

There is no ViewData item of type 'IEnumerable' that has the key 'SelectedRating'.

And.. now I've no idea where to fix it.

Model

   public class RateReviewVm {

        [Key]
        public System.Guid Id { get; set; }    
        [ForeignKey("User")]
        public System.Guid UserId { get; set; }    
        public virtual User User { get; set; }    
        [ForeignKey("Review")]
        public System.Guid ReviewId { get; set; }    
        public virtual Review Review { get; set; }    
        public bool HasLiked { get; set; }    
        public Nullable<int> Rating { get; set; }    
        //public int SelectedRating { get; set; }    
        public IEnumerable<SelectListItem> SelectedRating { get; set; }    
        public IEnumerable<SelectListItem> RatingList { get; set; }
    }

Controller

        [HttpGet]
        public ActionResult Rating(Guid id) {

            var options = new SelectList(Enumerable.Range(1, 10));

            var model = new RateReviewVm() { RatingList = options, ReviewId = id };

            return View(model);

        }
skylake
  • 409
  • 2
  • 9
  • 24
  • What do you mean _generates a footer_? Is your view using a layout that renders a footer? (and the errors occur because `Model.RatingList` is `null` because your not populating it when using the `Html.RenderPartial` method) –  Sep 30 '16 at 04:35
  • And your dropdownlist will never work - you cannot bind a ` –  Sep 30 '16 at 04:36
  • @StephenMuecke my view got no footer-code. I don't why footer appears when I'm doing it as I mentioned. I'm using `_Layout` from MVC template from Visual studio. I see, how do I populate it correctly? – skylake Sep 30 '16 at 04:40
  • @StephenMuecke If I use `int` `SelectedRating` then I get the error:`The ViewData item that has the key 'SelectedRating' is of type 'System.Int32' but must be of type 'IEnumerable'.` – skylake Sep 30 '16 at 04:41
  • That because you have not populated the `RatingList`. Refer [this question/answer](http://stackoverflow.com/questions/34366305/the-viewdata-item-that-has-the-key-xxx-is-of-type-system-int32-but-must-be-o). Your property MUST be `int SelectedRating` (as I have also stated in your previous questions) –  Sep 30 '16 at 04:43
  • And what is the code in the layout your using. You can always modify it or use a different layout. –  Sep 30 '16 at 04:44
  • @StephenMuecke I will check it out. The layout I'm using is [(this)](https://github.com/auth0/auth0-aspnet-owin/blob/master/examples/MvcSample/Views/Shared/_Layout.cshtml) – skylake Sep 30 '16 at 04:50
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/124604/discussion-between-stephen-muecke-and-skylake). –  Sep 30 '16 at 04:51

0 Answers0