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);
}