Please look at my code. I am trying to display some dynamic customers in the dropdown menu. And after selecting a customer button is pressed. Then products owned by the selected customer should be displayed in the textarea. But the problem is that after selecting a customer and pressing the button, nothing is displayed in the text area !. As i am new to ASP MVC can you help me out this problem?
Controller class-------------------->
public class ProductsController : Controller
{
CandidateEntities db;
public ProductsController()
{
db = new CandidateEntities();
}
public ActionResult Index()
{
ViewData["Customers"] = new SelectList(db.Customer.ToList(), "CustomerId", "Firstname");
return View();
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index(FormCollection form)
{
int customerId = int.Parse(form["Customers"]);
var cust = db.Customer.First(x=>x.CustomerId == customerId);
var Query =
from customer in db.Customer
join prod in db.Products on customerId equals prod.Customer.CustomerId
select prod;
ViewData["Products"] = Query.ToString();
return View("Index");
}
}
Index view------------------>
Index
<%using(Html.BeginForm()){ %>
<%=Html.DropDownList("Customers", "Seletc one")%>
<input type="submit" value="Click !" />
<%=Html.TextArea("Textarea", ViewData["Products"]) %>
<%} %>