Passing A List Of Object From A View To The Controller In Mvc?

Mar 26, 2010

ss a list of objects as a paramter in an actionlinkAt the moment when I try to do this the list is always empty by the time it reaches the controller!

<%= Url.Action("ActionName", new { list = Model.ListOfObjects}) %>
public ActionResult ActionName(List<Object> list)
{
//Do stuff
}

View 3 Replies


Similar Messages:

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

Passing Data From Controller To View Using JSon Object

Mar 4, 2011

I have the following to get the Json abject passed from the controller and populate the various textboxes in the view. However, nothing is happening even though controller is passing a valid Json object. What is wrong with this code?

<script language="javascript" type="text/javascript">
$(document).ready(function() {
var url = '<%=Url.Action("DropDownChange") %>';
$("#vendorID").change(function() {
var selectedID = $(this).val();
if (selectedID != "New Vendor Id") {
//$.post('Url.Action("DropDownChange","Refunds")', function(result) {
$.post(url, { dropdownValue: selectedID }, function(result) {
alert(selectedID);
$("#name").val(result.Name);
$("#city").val(result.City);
$("#contact").val(result.Contact);
$("#address2").val(result.Address2);
$("#address1").val(result.Address1);
$("#state").val(result.State);
$("#zip").val(result.Zip);
});
}
});
});
This is the code in my controller;
public JsonResult DropDownChange(string dropdownValue)
// This action method gets called via an ajax request
{
if (dropdownValue != null && Request.IsAjaxRequest() == true)
{
paymentApplicationRefund =
cPaymentRepository.PayableEntity(dropdownValue);
paymentApplicationRefund.Address1.Trim();
paymentApplicationRefund.Address2.Trim();
paymentApplicationRefund.Name.Trim();
paymentApplicationRefund.City.Trim();
paymentApplicationRefund.Contact.Trim();
paymentApplicationRefund.State.Trim();
paymentApplicationRefund.Zip.Trim();
return Json(paymentApplicationRefund,"application/json");
}
else
{
return null;
}
}

View 3 Replies

MVC :: Passing A List Of Entity Objects To View From Controller?

Aug 5, 2010

I need to pass a list of Entity Objects from Controller to View but not put it in the Model context. It is the users homepage, but I am putting a list of alerts on the users home page(somewhat like facebook). So I need the User Context as the Model I pass but need to pass the Alert model as well so I can show the list of alerts.. How would I do that? The code below is what I have so far..

UserController

[Code]....

UserRepository

[Code]....

View 1 Replies

MVC :: Passing A List Of Objects From View To Controller Via Jquery Ajax?

Jan 22, 2010

I have a form that I don't want to post back so I need to get the form values into my controller via jquery's ajax method.Here is my test controller method:

[Code]....

When I debug the controller method and look at the lineItems parameter, it always contains 0 items. I've tried various formats for the javascipt lineItems parameter but still 0 items. I'm also open to some other way of getting these values in like the jquery form serialze method or something else.

View 2 Replies

MVC :: Passing Data From Controller To View

Nov 16, 2010

I have setup an httppost that sends a string into my controller, searches for some results using linq, and then sends the results to a view. In debug stepping through the code I can see the data that I am looking for being passed into the return view statement, but the page just appears to refresh (it doesn't render the view as expected with the result). why my controller fails to redender the view? (note: I didn't include the view because I can send a ToList() to it without an issue. For example, return View(_entities.Persons.ToList());

[HttpPost]
public ActionResult RenderSearch(string usersearchtext)
{
if (usersearchtext != null)
{
var search_results = from s in _entities.Persons
where s.Description.Contains(usersearchtext)
select s;
return View("SearchResult", search_results.ToList());
}
else
{
throw new NotImplementedException();
}
}

View 8 Replies

MVC :: Passing Objects Between View And Controller?

Sep 2, 2010

I would like to pass List<SelectListItem> (not selected item but the whole "List" object) back to controller.

for example in my GET controller i would have this

ViewData["list"] = some select list from repository;

then on post I would like to get the list back from view..pretty much i'm trying to use ViewData["list"] as storage..this way I would use ajax to remove or add items to/from the list.

View 10 Replies

Passing Data From A View To A Controller In MVC?

Apr 22, 2010

I have a dictionary I'm passing to a View. I want to be able to pass the values of that dictionary back to a Controller action from this same View. Is there anyway this can be accomplished without using a form? The situation is that I need to be able to pass these back to a controller action that is called when a user clicks an ActionLink from the View, and in my experience an ActionLink cannot be used to submit a values of a form, i.e. I've only been able to submit values of a form using the form's submit button. Unless there's a way to use an ActionLink to submit values in a form.Controller Action passes Dictionary to Controller in ViewData:

public ActionResult ModifyNewCrossListing(FormCollection form)
{
Dictionary<int, string> prefixlist = new Dictionary<int, String>();

[code]...

View 1 Replies

MVC :: Passing Data From View To The Controller With Dropdownlist

Jul 14, 2010

I have a table with a ID, CodeID,LibelleID field. I am using oracle connection. i want to display in a drop downlist (textfield) CodeID+LibelleID for exemple "100-SalaryBase" where CodeID=100 and LibelleID="SalaryBase" is it possible to obtain it if the user selects an element from the dropdownlist how to post both the codeID and ID to the controller

View 4 Replies

MVC :: Passing Data From View Back To Controller

Sep 23, 2010

I have following situation - I am pasing user info object from Controller to View. It contains GUID UserID, which i dont want to be seen on page. So I removed every Html.LabelFor(model => model.UserID), Html.TextBoxFor(model => model.UserID) etc... from generated View source. And because of this when Html.BeginForm() returns that object back to Controller all values is there but UserID is lost??

If I leave Html.LabelFor(model => model.UserID), Html.TextBoxFor(model => model.UserID) etc.. in View everything is fine. But I dont want to show UserID? Where is the problem here?

<%= Html.LabelFor(model => model.C__User_Id) %>

View 6 Replies

MVC :: Passing ViewModel With Data From View To Controller

Dec 13, 2010

I am trying to pass a view model of mine, which has multiple list in it, to my view. Then in my view i need to edit the different list. Then on my post i need to save the edits. Although, when i pass my viewmodel back to my post, it is empty! Can somebody explain what i am doing wrong? Controller

[Code]....
here is my View

[Code]....

NewsViewModel

[Code]....

View 2 Replies

MVC :: Passing Boolean Values To View From Controller?

Jan 20, 2010

I'm having problems passing values from the controller to the view. I created a boolean variable to use as a flag and want the view to render some html based on whether its true or false.

Unfortunately ViewData doesn't look like it can pass boolean values. I should be able to pass any datatype to a view (string, int, bool, etc...)

View 16 Replies

MVC :: Methods To Passing Additional Data From Controller To View

Apr 29, 2010

I am getting started with Ap.net MVC. For that i chose to practice it by build an application. Im using MVC 2 and Linq To SQL, and i would like to passing another Query to the view. For example, i have this:

[Code]....

So i would like to pass data1 and data2 to the View. I can use return View(data1), but the View function accept just one data. So what technique i can use to pass the tow data to the view

View 5 Replies

MVC :: How To Create List Of Custom Object In Controller

Jan 2, 2011

In my controller I fetch a list of object 'object1' which has two fields field1 & field2.Now I have a model model1 which has two fields fieldsX & fieldY.fieldX = field1fieldY = dosomething(field2 also have a view model ViewModel1 which has a single fieldpublic List<model1> model2I need to send model2 to my view

View 4 Replies

MVC :: Passing The Object From View To View ?

Mar 3, 2011

i have an MVC 1 application in vs 2010, it uses the session to pass around the object from viewmodel to view model as it needs it I am seeing issues using this way due to the fact that after a time limit the object loss thier state I want to avoid this, what would be the best practice on passing the object from view to view along with the changes that occur to along the way.even if these changes ARE not persisted to a database meaing only exsisting in that user instance until the workflow completes and they actually save the item...

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

Web Service - Passing A Base Object With List / Collection?

Apr 9, 2010

We need to create a simple web service in ASP.NET that can be called from PHP or other languages. This in turn will be used to update records in a database for an item submission.

The core part is fairly simple, we have a base set of fields for the object - first name, last name, birth date, city, etc. In addition however we need to accept a list of items associated with that object that can range from 0-n.

Jan 1 2009, ABC
May 1 2010, 123
Jun 30 2010, XXXXX

What would be the best way to structure this so it can be easily passed to the ASP.NET web service and processed as a single call for the entire object? Would passing the list of items as a single delimted string be a wise approach? Ex: Jan 1 2009, ABC|May 1 2010, 123|Jun 30 2010, XXXXX

View 1 Replies

MVC :: Passing Json Collection Object From View To Action

Nov 1, 2010

I am trying to send json data from view to controller action. But the issue is the data is not populating in the action parameter List<Score>.

View Model:
public class Score
{
public int QuestionId { get; set; }
public int PrevAnswerId { get; set; }
public int CurrAnswerId { get; set; }
public string CurrAnswerName { get; set; }
}

Json Data look like:
[
{QuestionId:1, PrevAnswerId:3, CurrAnswerId:3, CurrAnswerName:'Known to Broker'},
{QuestionId:2, PrevAnswerId:7, CurrAnswerId:7, CurrAnswerName:'Completed'},
{QuestionId:3, PrevAnswerId:10, CurrAnswerId:10, CurrAnswerName:'Report'}
]

On window load, I will construct the Json object using "eval()" function and do some operation in the data before its save. On Save Click, I will call the action through the ajax call.

$.ajax({
url: url,
type: "GET",
dataType: 'json',
data: {score: ScoreJson},
contentType: "application/json; charset=utf-8",
success: function () {
alert("succes");
},
error: function () {
alert("error...");
} });

Action:
public ActionResult SaveScore(List<Score> score)
{
// do something...
}

But here score comming as collection of 3 elements with zero(for interger property)/null(for string property) values. When I checked in the request I found the data in "parama" property like.

"Score%5b0%5d%5bQuestionId%5d=1 &Score%5b0%5d%5bPrevAnswerId%5d=3 &Score%5b0%5d%5bCurrAnswerId%5d=3 &Score%5b0%5d%5bCurrAnswerName%5d=Known+to+broker&
Score%5b1%5d%5bQuestionId%5d=2 &Score%5b1%5d%5bPrevAnswerId%5d=7 &Score%5b1%5d%5bCurrAnswerId%5d=7 &Score%5b1%5d%5bCurrAnswerName%5d=Completed&
Score%5b2%5d%5bQuestionId%5d=3 &Score%5b2%5d%5bPrevAnswerId%5d=10 &Score%5b2%5d%5bCurrAnswerId%5d=10 &Score%5b2%5d%5bCurrAnswerName%5d=Travelers+Report&".

But I am not sure why it is not getting populated in the score list. One full day I spent for this issue but till now I didnt find the solution for this issue.

View 4 Replies

C# - Using Grasp Controller With MVC Controller - How To Make An Object Always Visible For A Controller

Dec 28, 2010

UML and Patterns: An Introduction to Object-Oriented Analysis and Design and Iterative Development, that follows the UP(Unified Process). It uses a Grasp Controller pattern to interact with domain classes by some methods like NewSale(), AddNewItemToSale() and CloseSale. In windows form, I can instantiate a object of this class in the UI and then use its methods to perform the actions. This works well in Client apps, but when I use asp.net mvc, I cannot find a way to instantiate an object (one for each user) that was always visible for a Controller (MVC). I cannot insert as an attribute inside Controller because it always create a new one.

View 1 Replies

Forms Data Controls :: Passing Dynamic Value To Detail View Of Grid Through Object Selecting Parameter

Oct 4, 2010

Passing dynamic value to Detail view of grid through object selecting parameter

View 4 Replies

Forms Data Controls :: Dropdown List Not Passing Info To Details View?

Jan 12, 2010

'm using a textbox to get the first 5 letters of the name.

An sqldatasource then finds the people who have names > than the five letters and picks up their ID numbers as well as their names.

After that I use a second sqldatasource to get one individual from that dropdownlist's persons name and id number and then using a detailsview I display that person.

Well both sqldatasouces work fine but it just does not pass the ID number when I debug it.

View 9 Replies

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

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

MVC :: File Not Passing To Controller?

Aug 23, 2010

I am getting an null referance on file, what am I doing wrong.

<% Html.EnableClientValidation(); %>
<% Html.BeginForm("AddMedia", "Pattern", new { id= Model.Pattern_Guid} , FormMethod.Post, new {enctype = "multipart/form-data"}); %>
<%: Html.ValidationSummary(true) %>
<%: Html.Label("height") %>
<%: Html.TextBox("height") %>
<%: Html.Label("width") %>
<%: Html.TextBox("width") %>
<%: Html.Label("Media") %>
<input type="file" id="Media" name="Media" />
<input type="submit" name="btnAdd" value="Add" />
<% Html.EndForm(); %>

controller code:

[HttpPost]
public ActionResult AddMedia(Guid id, HttpPostedFileBase file, FormCollection collection)
{
string mimeType = file.ContentType; // Null Exception here ....

View 2 Replies

MVC :: Passing Tag Id To Controller When User Click On?

Jun 12, 2010

When user click on <a> tag i want to pass the id value to controller

View 1 Replies







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