Validation showing games that not ment to be on dropdown?

Up vote 0 down vote favorite share g+ share fb share tw.

Hi people I have the following controller called review: using System; using System.Collections. Generic; using System. Data; using System.Data.

Entity; using System. Linq; using System. Web; using System.Web.

Mvc; using GameTest. Models; namespace GameTest. Controllers { public class ReviewController : Controller { private gamezoneDBEntities db = new gamezoneDBEntities(); // // GET: /Review/ public ViewResult Index() { var Info = db.tblReviews.

Include(x => x. TblGame). Where(UserInfo => UserInfo.UserName.

Equals(User.Identity. Name)).ToList(); return View(Info); } // // GET: /Review/Details/5 public ViewResult Details(int id) { tblReview tblreview = db.tblReviews. Find(id); return View(tblreview); } // // GET: /Review/Create public ActionResult Create() { var userGames = db.tblGames.

Where(g => g. UserName == User.Identity. Name); ViewBag.

GameIDFK = new SelectList(userGames, "GameID", "GameName"); return View(new tblReview { UserName = @User.Identity. Name }); } // // POST: /Review/Create HttpPost public ActionResult Create(tblReview tblreview) { if (ModelState. IsValid) { db.tblReviews.

Add(tblreview); db.SaveChanges(); return RedirectToAction("Index"); } ViewBag. GameIDFK = new SelectList(db. TblGames, "GameID", "GameName", tblreview.

GameIDFK); return View(tblreview); } // // GET: /Review/Edit/5 public ActionResult Edit(int id) { tblReview tblreview = db.tblReviews. Find(id); ViewBag. GameIDFK = new SelectList(db.

TblGames, "GameID", "GameName", tblreview. GameIDFK); return View(tblreview); } // // POST: /Review/Edit/5 HttpPost public ActionResult Edit(tblReview tblreview) { if (ModelState. IsValid) { db.

Entry(tblreview). State = EntityState. Modified; db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.

GameIDFK = new SelectList(db. TblGames, "GameID", "GameName", tblreview. GameIDFK); return View(tblreview); } // // GET: /Review/Delete/5 public ActionResult Delete(int id) { tblReview tblreview = db.tblReviews.

Find(id); return View(tblreview); } // // POST: /Review/Delete/5 HttpPost, ActionName("Delete") public ActionResult DeleteConfirmed(int id) { tblReview tblreview = db.tblReviews. Find(id); db.tblReviews. Remove(tblreview); db.SaveChanges(); return RedirectToAction("Index"); } protected override void Dispose(bool disposing) { db.Dispose(); base.

Dispose(disposing); } } } This is my crete view: @model GameTest. TblReview @{ ViewBag. Title = "Create"; } Create @using (Html.BeginForm()) { @Html.

ValidationSummary(true) tblReview @Html. LabelFor(model => model. ReviewID) @Html.

EditorFor(model => model. ReviewID) @Html. ValidationMessageFor(model => model.

ReviewID) @Html. LabelFor(model => model. Recomendation) @Html.

EditorFor(model => model. Recomendation) @Html. ValidationMessageFor(model => model.

Recomendation) @Html. LabelFor(model => model. AvoidOrBuy) @Html.

EditorFor(model => model. AvoidOrBuy) @Html. ValidationMessageFor(model => model.

AvoidOrBuy) @Html. LabelFor(model => model. Score) @Html.

EditorFor(model => model. Score) @Html. ValidationMessageFor(model => model.

Score) @Html. LabelFor(model => model. GameIDFK, "tblGame") @Html.

DropDownList("GameIDFK", String. Empty) @Html. ValidationMessageFor(model => model.

GameIDFK) @Html. LabelFor(model => model. UserName) @Html.

EditorFor(model => model. UserName) @Html. ValidationMessageFor(model => model.

UserName) } @Html. ActionLink("Back to List", "Index") My problem is, when I run the application and fill in the all fields apart from choosing a game the validation shows me that I have to choose a game, but teh strange is I have code to stop showing other users games in the review, but when the validation kicks in, it shows the other users games within the list. Is there a way to stop the validation showing the reviews of other users that posted a game.

Because the code works it only happens when I don't select a game. The code for making the games unique is which is placed in the first CREATE function : var userGames = db.tblGames. Where(g => g.

UserName == User.Identity. Name); ViewBag. GameIDFK = new SelectList(userGames, "GameID", "GameName"); return View(new tblReview { UserName = @User.Identity.

Name }); also I would like a way once the user selects a game, it is removed from the drop down Thank You c# asp.net asp.net-mvc-3 link|improve this question asked Apr 6 at 21:26user1137472838 42% accept rate.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions