how to pass data between controller to view [Resolved]

Posted by Srujana under ASP.NET on 5/23/2012 | Points: 10 | Views : 1231 | Status : [Member] | Replies : 4
Hi,
I am developing a web application using asp.net mvc3.
I have 3 model classes(code first)
ProductGroup(parent)->Product(child)
then while creating a new product productgroup names come int the drop down list by writing the following code
in controller,
ViewBag.ProductGroupID = new SelectList(db.ProductGroups, "ProductGroupID", "Name", product.ProductGroupID);
in view:
<div class="editor-label">
<%: Html.LabelFor(model => model.ProductGroupID, "ProductGroup") %>
</div>
<div class="editor-field">
<%: Html.DropDownList("ProductGroupID", String.Empty) %>
<%: Html.ValidationMessageFor(model => model.ProductGroupID) %>
</div>
and
product(parent)->PreferedLocation(child)
now my requirement is I have to create a preferedlocation for each individual product,means while creating a new preferedlocation the the particular product name will have to display
only single product not in drop down ,
how to do this one ,
if any one know the answer plz help me.




Responses

Posted by: Srujana on: 5/24/2012 [Member] Starter | Points: 25

Up
0
Down
Hi ,
Thanks for giving reply,
I wrote the following code but it displays productid but I need Product name.
in controller:
public ActionResult selectlocation(int id)
{
PreferredLocation preferedlocation = new PreferredLocation();
Product prodcut=new Product();
ViewBag.ProductID=id;
return View();


}

//
// POST: /Product/Create

[HttpPost]
public ActionResult selectlocation(PreferredLocation preferedlocation)
{
if (ModelState.IsValid)
{
//product.UserName = SessionHelper.GetUserName();

db.PreferredLocations.Add(preferedlocation);
db.SaveChanges();
return RedirectToAction("Index");
}


return View(preferedlocation);
}
in view:

<div class="display-label">Product</div>
<div class="display-field">

<%: Html.Display("ProductID")%>
</div>
I tried it for different ways but I cant display it.

Srujana, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Chikkanti on: 5/26/2012 [Member] Starter | Points: 25

Up
0
Down
hi.... srujana... i think u want to display multiple values in dropdownlist.... for this please visit....
http://chikkanti.wordpress.com/2012/05/02/how-to-bind-dropdownlist-in-asp-net-mvc3-dynamically/
or comment with full explanation in myblog with code...

chikkanti

Srujana, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Srujana on: 5/26/2012 [Member] Starter | Points: 25

Up
0
Down
Thanks,your reply helps me

Srujana, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response