You might also get a id from tblreview without the need of form collection.
Up vote 0 down vote favorite share g+ share fb share tw.
Hi guys I want a way where when a user selects a value from a drop down and inputs the values that are on the interface and then value from the drop down is cleared and no longer able to be selected. Here is my model: namespace Game. Models { using System; using System.Collections.
Generic; public partial class tblReview { public int ReviewID { get; set; } public string Recomendation { get; set; } public string AvoidOrBuy { get; set; } public string Score { get; set; } public int GameIDFK { get; set; } public string UserName { get; set; } public virtual tblGame tblGame { get; set; } } } and here is my controller: using System; using System.Collections. Generic; using System. Data; using System.Data.
Entity; using System. Linq; using System. Web; using System.Web.
Mvc; using Game. Models; namespace Game. 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"); } 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 }); } // // 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); } } } and here is the view: @model Game.
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") Your Help will be much thanked if there is anything that is required please ask. C# asp.net asp.net-mvc-3 asp.net-mvc-3-areas link|improve this question asked 2 days agouser1137472818 42% accept rate.
2 I'm a little confused about what you're asking. So the user sees a form. They click the dropdown, and from the dropdown they select "Warcraft II".
Now you want to immediately remove Warcraft II from the list? – StriplingWarrior 2 days ago yes from the dropdown list not the database – user1137472 2 days ago That is correct what you said – user1137472 2 days ago when they submit and it redirected back to the same view or when they just select onchange – COLD TOLD 2 days ago I want it so when they submit the value it is redirected to the same page so they can select another game an so on but the value that has allready been selected should not show in the list – user1137472 2 days ago.
You might also get a id from tblreview without the need of form collection @Html. DropDownList("GameIDFK", String. Empty) @Html.
ValidationMessageFor(model => ViewBag. GameIDFK) HttpPost public ActionResult Create(tblReview tblreview, FormCollection formCollection) { if (ModelState. IsValid) { db.tblReviews.
Add(tblreview); db.SaveChanges(); // return RedirectToAction("Index"); } int gameid=Convert. ToInt32(formCollection"GameIDFK"); var userGames = (from g in db. TblGames where g.
UserName== User.Identity. Name && g. GameID!
=gameid select g).ToList(); ViewBag. GameIDFK = new SelectList(userGames, "GameID", "GameName"); return View(new tblReview { UserName = @User.Identity. Name }); }.
It removes one value and then when I select the another value the pervious value comes back. I wanted it so when a user selects a game i. E gta and then presses submit the value goes away and not to be selected again like my post states.
– user1137472 2 days ago also when I log off the value comes back. I want a way which a user selects a game inputs all the values on the interface and then submits tha value goes from the drop down an no longer be able to selected. So once a review is entered that is it the game can no longer be selected thanks for the answer was pretty close to what I wanted thanks – user1137472 2 days ago now I understand you more clear it more toward database de.
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.