C# - Pass Nested Lists From View To Controller Using Viewmodels?

Mar 24, 2011

I am Francesco and I am newbie. I have a problem with ASP.NET MVC3 regarding the data posted between View and Controller. My goal is to use a form to edit a specific record from my database and then post it back to the controller, which is in charge of checking the record's fields and submit them into the database.
The data are passed from the Controller to the View by using a ViewModel and therefore the DefaultDataBinding does not apply in this case. I tried many approaches, I monitored the communication with Fiddler but I couldn't solve my problem. The method described by Phil Haack does not work and neither does the FormCollection.

Here you have the code:

ViewModels: I pass it to the View to create a table. Name and the list of Item names (table columns headers) are just to be displayed. I want to have back the Id, the Month (they are passed correctly as parameters and represents table row headers) and most important the ActualValue of the Items and their Id (I have an association table in my database with Id, Itemid and Month as keys)

[Code]....

View: The View is strongly typed as ViewModels.EditViewModel and sends the fields through a submit button. I have to generate a table by using foreach loops, because I do not know how many items there are in advance

Controller: The controller has to update each kpi passed from the view related to a specific Id and Month.

[HttpPost]
public ActionResult EditMonth(int Id, int Month, //FormCollection kpiValues)

View 1 Replies


Similar Messages:

MVC :: Pass Parameter From Controller To View And Back To Another Controller?

Aug 16, 2010

I have a simple model where a Person has Gifts. I have a view which is a list of Gifts belonging to one Person.

My problem is with the Create action for a new Gift. I want it to default to the PersonID that we are already viewing the list of Gifts for. I tried simply passing the last PersonID (they are all the same)

Html.ActionLink("Create New", "Create", new { id = Model.Last().PersonID }) which works fine if there is already at least one Gift for that person but if this is the first Gift I don't have a value.

My Gift List controller knows the PersonID I want to pass but the view doesn't.

How do I pass this PersonID from my Gift List controller to my Gift Create controller via the Gift List view? Or is there a better way to do this?

View 2 Replies

How To Get ID Of EditorFor With Nested Viewmodels In Mvc 2

Mar 30, 2010

So I have two nested view models, CreditCard -> BillAddress. I have a view, "EditBilling", that has EditorFor(CreditCard). The CreditCard EditorTemplate has EditorFor(BillAddress), and the BillAddress EditorTemplate has EditorFor(BillState).

The end result is a select list with id "CreditCard_BillAddress_BillState".

I need to reference this in javascript, thus need to know the ID. In other situations, with non-nested ViewModels, I have used the following code:

$('#<%= ViewData.ModelMetadata.PropertyName %>_BillState')

The problem here is that the ModelMetadata.PropertyName property is only aware of the current property, not the parent(s). So I end up with the following:

$('#BillAddress_BillState')

How does one go about getting the client ID of nested strongly typed helpers?

View 1 Replies

MVC :: Trying To Pass A Parameter From A View To Another Controller

Apr 18, 2010

i have a view /categoria/index

[Code]....

i am trying to call the action from /imovel/index

with an id

but the thing is that i am getting null

[Code]....

View 2 Replies

MVC :: Pass Message From Controller To View Using Viewdata

Feb 13, 2011

I want to pass a message from the controller to a view using Viewdata. Here is my code:

public ActionResult Create(FormCollection createPage)
{
try
{
......................
ViewData["Message"] = "Success - rec added!!!!" ;
return RedirectToAction("Index");
}
catch (Exception e)
{
ViewData["Message"] = "Exception: " + e.ToString();
return RedirectToAction("Index");
}

On my View I have:

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>::><%: ViewData["Message"] %><::</h2>
<h3>==><%= ViewData["Message"] %><==</h3>
<p>

This is Index.aspx page in Controller folder

</p>
</asp:Content>

I am getting result with empty ViewData["Message"]

View 4 Replies

MVC :: How To Pass Specific Information From View To Controller

May 25, 2010

My view has a number of rows.

Each row has a drop down, a text box and an "add" link. I'd like for someone to select something in the drop down, edit something in the text box and pass that information to an Action in the Controller.

I know i can do something like this:

[Code]....

[Code]....

Which is kind of gross - id like to do just call one action, that passes the selected drop down value, the textbox value and call just the one action, is it possible to do something like this:

[Code]....

Where i pass the Dropdownlist selection and the textbox value to my controller specifically

View 3 Replies

How To Pass All The Local Variables In One Controller To View

Jan 16, 2011

In asp.net mvc3, I've got a few local variables in one of the controller, is there any neat way to pass all these variables to view? Something like "locals()" in python?

View 1 Replies

MVC :: How To Pass Strong Typed List From View To Controller

Jun 15, 2010

[Code]....

for List<AnswerInfo>,

[Code]....

now, what i want to do is to place few textboxes on a view that allow users to input the Answer Text. after click the submit button. i want List<AnswerInfo> which contains the Text information pass to the controller. can anyone tell me how to do it?

View 4 Replies

MVC :: How To Pass Data (not The Part Of Model) From View To Controller

Oct 8, 2010

How Can I Pass data(not the part of model) to Controller from View? View Code

[Code]....

View 4 Replies

C# - How To Pass A Value From MVC Controller To Webforms Control Inside MVC View

Dec 24, 2010

My way to ASP.NET MVC was not across ASP.NET Web Forms, so it's hard for me to understand how better to pass value from ASP.NET MVC controller to ASP.NET webforms script which is inside MVC View.

For example, controller action:

[Code]....

How to assign a value of myvar from a controller action to par1 variable in the View instead "stubvalue"?

View 3 Replies

MVC :: How To Pass Some Dynamic View Data To A Controller And Then To Java Script Function

Mar 24, 2010

Well i am a sort of a beginner..

I am writing an Application using mvc and c#..

Well i have a View where i have the following code..

[Code]....

View 1 Replies

MVC :: How To Pass A Dictionary Type Of Data From View To Controller Using A HtmlHelper Control

Jun 17, 2010

if I use a Html.Hidden field in my view, when the value click to submit the form I would like to pass this data to the controller. This variable would contain int as key and string as value,

Dictionary<int, string> interestTable = new Dictionary<int, string>();

How can I specify the htmlAttribute fo this variable in my Html.Hidden code?

<% using(Html.BeginForm("Search", "SearchMembers")) { %>
<input type="hidden" name="ResearchInterests" id="researchInterests" value=""/>
<%= Html.Hidden("fullInterestsPath") %>,

View 5 Replies

Data Controls :: How To Pass Data From View To Controller In MVC

Apr 15, 2014

how can we pass data from view to controller in Asp.net mvc

View 1 Replies

MVC :: - View - Passing Multiple Objects To The View And Selecting Data From The Lists?

May 17, 2010

I have a view which takes two objects: booking and list of reasons for canceling that booking.I have two classes: clsBooking, clsBookingCancelationReason I can read both objects in my view - no problems there. After I read the objects, I display the booking details and I generate a list of cancelation reasons in the following way:

[Code]....

The code above generates a list of cancelation reasons.How do I pick up the selected ReasonId from the list?
I need to generate a link that will contain the bookingId and the selected reason for canceling the booking.I can get the bookingId out easily since it's stored in the Model...but how do I go about the selected ReasonId?

View 5 Replies

Forms Data Controls :: Pass A Value To The 2 Master / Detailed Drop Down Lists?

Oct 5, 2010

using below code, I bind 2 drop down lists.

[Code]....

And using the below code, I pass the content of a cell of GridView selectedRow to those DopDownLists .

[Code]....

But there is an error when I try to change the selected value of ddlCity (Detail)...What shall I do ?

View 5 Replies

MVC :: Create A Partial View And A Controller That Will Feed Data To the View?

Jan 27, 2010

Can i create a partial view and a controller that will feed data to the view, and if i render that partial in a Master page, the Data will show on whatever URL i am?

Or is there another way of showing content from database on every page(view)?

View 2 Replies

Asp.net - Grid View - View State For Nested Controls?

Jul 14, 2010

I have a grid view with a nested text box in it.I would like to turn view state off but the fact of the matter is when data is posted,the text boxes inside the gridview aren't available (there are no rows in the gridview on postback). Control's information is not stored in the View State (for things like selected value and .text etc.):Control state,introduced in ASP.NET version 2.0, is similar to view state but functionally independent of view state.However,control state cannot be disabled. Control state is designed for storing a control's essential data (such as a pager control's page number) that must be available on postback to enable the control to function even when view state has been disabled. Source: http://msdn.microsoft.com/en-us/library/1whwt1k7.aspx

View 2 Replies

MVC :: Passing Model Object To View And From View To Controller?

Aug 6, 2010

I've got problem with my app .

I've got such classes (this is some kind of tree structure):

[Code]....

[Code]....

in Index() action i've got this piece of code

[Code]....

[Code]....

View 2 Replies

Visual Studio 2010 - Can View Lists During Debug Results In Timeout

Oct 26, 2010

I am trying to debug a project, suddenly I'm running into an issue where enumerating any object collections results in a timeout if I try to view it.If I run the program normally I have no issues. If I try to view any collection, such as a list, I get a timeout error and the whole thing bombs out.I thought something might be going on with one of my more complex collections so I tried creating just a normal list of strings as follows...

List<string> blah = new List<string>{"fsdf","fsdg","Gt","gsersg","ser","gersgxdrsd"};

View 1 Replies

Forms Data Controls :: Unable To Update The Data In Nested Data Lists?

Feb 16, 2011

i am unavble to update the data in nested data lists in asp.net, if any one have the code

View 3 Replies

C# - How To Pass Value To Controller

Aug 25, 2010

I have a drop down where I want to pass the selected value I selected to the controller. How do I accomplish this?

View 2 Replies

MVC :: Pass The URL ID To Another Controller?

Nov 15, 2010

I have an action:

public ActionResult Details(int? aaaID, int? bbbID)

and I am trying to route the url http://..../controller/aaa/23432 to action Details.

routes.MapRoute( "controller", // Route name "controller/aaa/{id}", // URL with parameters new { controller = "controller", action = "Details", lblID = UrlParameter.Optional } // Parameter defaults);However, the aaaID of function Details also get a null value?

View 1 Replies

Mvc Ajax How To Pass The Id As Well To The Controller

Mar 15, 2011

[code]....

i am having problem passing in passing the url id to the controller with the form . how can i do that ?

View 3 Replies

MVC :: How To Pass DropDownList Value To Controller

Oct 4, 2010

In my ASP MVC app I have an asp: DropDownList control that has a source of a Linq data class. The values in the list are getting set fine, but when I select one, and then click on an Html.ActionLink, and pass control back to my controller, I'm not sure how to fetch the value that was selected from the DropDownList.

View 1 Replies

MVC :: How To Pass SelelctList Into Controller

Jul 29, 2010

How Can I Pass SelectList into Controller?

here is my code

[Code]....

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved