how to pass data between controller to view

Posted by Srujana under ASP.NET on 5/23/2012 | Points: 10 | Views : 1105 | 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: Fool2code on: 5/23/2012 [Member] Starter | Points: 25

Up
0
Down
Your description is quite unclear. Can you correct the grammatical mistakes and then post your code in more organized manner to help you out.

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

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

Up
0
Down
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<Carrots.Web.Models.Product>>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Index
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

<h2>Index</h2>


<%: Html.ActionLink("Create New", "Create") %>
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp
<%: Html.ActionLink("Show All Active Products", "Show") %>
<table>
<tr>
<th>
Name
</th>

<th>
ColliType
</th>

<th>
ProductGroup
</th>
<th>
CurrentLocation
</th>

<th>
AvailableFrom
</th>
<th>
AvailableTo
</th>
<th>
Note
</th>

<th>
UserName
</th>
<th></th>
</tr>

<% foreach (var item in Model) { %>
<tr>
<td>
<%: Html.DisplayFor(modelItem => item.Name) %>
</td>

<td>
<%: Html.DisplayFor(modelItem => item.ColliType.Name) %>
</td>

<td>
<%: Html.DisplayFor(modelItem => item.ProductGroup.Name) %>
</td>
<td>
<%: Html.DisplayFor(modelItem => item.CurrentLocation) %>
</td>
<td>
<%: Html.DisplayFor(modelItem => item.Country.Name) %>
</td>
<td>
<%: Html.DisplayFor(modelItem => item.AvailableFrom) %>
</td>
<td>
<%: Html.DisplayFor(modelItem => item.AvailableTo) %>
</td>
<td>
<%: Html.DisplayFor(modelItem => item.Note) %>
</td>

<td>
<%: Html.DisplayFor(modelItem => item.UserName) %>
</td>
<td>
<%: Html.ActionLink("Edit", "Edit", new { id=item.ProductID }) %> |
<%: Html.ActionLink("Details", "Details", new { id=item.ProductID }) %> |
<%: Html.ActionLink("Delete", "Delete", new { id=item.ProductID }) %>
<%:Html.ActionLink("PreferedLocation", "selectlocation", new { id = item.ProductID })%>//exception came as id as preferedlocation id but passed productid
</td>
</tr>
<% } %>

</table>

</asp:Content>


when I select preferedlocation(action is selectlocation) I need to create preferedlocation for individual product.
o/p as:
product,
Mango,
textboxes for entering preferedlocation data.

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

Posted by: Fool2code on: 5/23/2012 [Member] Starter | Points: 25

Up
0
Down
Update this line :

<%:Html.ActionLink("PreferedLocation", "selectlocation", new { id = item.PreferredLocationID })%>


See if the change help:)


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

Login to post response