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


Similar Messages:

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 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 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

MVC :: Using Data From Multiple Entity Framework4 Model Entity Objects In MVC2 Controller?

Sep 29, 2010

getting data from multiple Entities models into an MVC controller. Most of the examples I have seen for using EF in an MVC2 app only use a single entitiy.

I have just started using MVC2 in C# using the Entity Framework models (CIOps.model) created from an SQL database. I can create the controller and views using single tables of the model in MVC2, but I just cannot get my head around how to get data from multiple entity tables into the controller (similar to joins in T-SQL). I have included an example below of the controller code that works with a single entity table, tbl_tours (tbl_tour in DB).

Could someone please illustrate how this code would be changed to include additional columns from FK tables in addition to tbl_tours columns. E.g. the clients name from the tbl_clients, the coordinators name from the tbl_employees, and costs from tbl_costs entities? Is it possible to do this directly using the EF model entities/classes that are already created and not use LINQ, POCO, Repositories, etc.? The FK relationships are already in the EF models. I have included the whole controller code, but I just need a few examples of how to join the multiple entities, not rewrite every CRUD function function in the controller. I think this will get me over the hump in using EF in an MVC2 App. Also ignore the fact I am using the home controller, this will change in the application.

[Code]....

View 21 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

MVC :: Passing A Collection Of Objects To The View?

Apr 16, 2010

I'm trying to pass a list of items from a LINQ query to a View, but I'm having trouble figuring out how to resolve a type issue. Here's the error:

The model item passed into the dictionary is of type 'System.Data.Linq.DataQuery`1[Project.Models.Diagnostic]' but this dictionary requires a model item of type 'Project.Models.Diagnostic'.

The issue seems to originate with this code from my Controller:

[Code]....

I tried changing the IQueryable<Diagnostic> to var and got the same error. Also played around with something like:

[Code]....

But then VS2008 says that diagnostics could never be null, and that's may not the best (or even valid) way to do it.

View 1 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

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

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

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 :: Load Partial View With List Of Objects?

Jul 8, 2010

I'm really new to MVC (just started a few weeks ago) and new to Ajax (never looked at it before today). I need some design / technical advice concerning Ajax, MVC, loading partial views, and posting / getting from a view. What I'd like to do it load a partial view that takes in a list of objects that have been queried from my db into an details-type view. The details view already has some other content that has been handeled and loaded from information pulled from my database and setup through some actions. It is strongly types to a model.

Below is the partial view I've created thus far:

[Code]....

And here's a portion of the Details page:

[Code]....

I'm not sure what to do for the Ajax.ActionLink. I'd like for a use to be able to type into the text box on it's left and hit "Add" (the Ajax link) and have the application add the content in the text box to the database. Should it be something else? An <input>? The Controller code piece is below:

[Code]....

So it should be adding the member into the repo / db and then reload the contents of the partialview. Instead, it's reloading the whole page and not just the partial view. (the url is changing from /project/details/5 to /project/membersection/).

View 10 Replies

C# - How To Dynamically Build A List Of Objects In A Create View

Jul 9, 2010

I have an Employee model that has a Name and Company

I want to be able to build multiple Employees in one CREATE view. I figured I need to create an IList<Employee> and do something like:

<%= Html.TextBoxFor(m => m[0].Name) %>
<%= Html.TextBoxFor(m => m[0].Company) %>
<%= Html.TextBoxFor(m => m[1].Name) %>
<%= Html.TextBoxFor(m => m[1].Company) %>

If a user clicks on "Add another employee", I want the view to make another form for the new employee:

<%= Html.TextBoxFor(m => m[3].Name) %>
<%= Html.TextBoxFor(m => m[3].Company) %>

And continue to add form items (and increment the array index if they click on it again).

Keep in mind that I need to build the form and the list dynamically in the create view. I don't already have a populated list of Employees.

View 1 Replies

MVC :: Use Gridview Or List View With ADO.net Entity?

Apr 1, 2011

i am working on MVC 2.0 , i would like to use gridview and list view as i am trying to display the product page for a shopping cart solution.

can i use them if yes then how and if not what could be the alternative solution to display product with shopping cart button and how can i pass parameter to display product when somebody click on the product view more detail.

View 5 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

Forms Data Controls :: Binding A Repeater To A List Of Objects That Have Child Objects?

Nov 17, 2010

have some Objects, lets say Employee and Role defined as below and I have defined relationships in my database that gives me a list of objects say employees and thanks to my framework each employee object also has a Role object linked via the RoleIDID, UserName, Password, Email, RoleIDRoleID, RoleNameSo in code I can do something like this

Employee emp = dataService_GetEmployeeByID(1);
string RoleName = emp.Role.RoleName;

Now here is my problemI can bind any object in a repeater and it works fine for the first level in my relationship

For instance <%# Eval("UserName") %>

But I need to be able to show the details for my child objects as well (Role) so something like this (which does not work)

<%# Eval("Role.RoleName") %>

View 2 Replies

Forms Data Controls :: Binding An Objects(containing Sub Objects) To A Dropdown List?

Apr 6, 2010

I know how to bind a simple objects to a dropdown list. However I am having problems binding my objects which contains sub objects to the control.i.e. with simple object i just do ddl.DataValueField = "myproperty"
with my objects they contains sub objects which i want to bind. I have tried ddl.DataValueField = "sub-object.myproperty" which doesnt work.

View 2 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 :: Update Related Objects In Controller

May 29, 2010

I have and Article object that I update in my controller.... the object is passed into the controller and then I just call UpdateModel(inArticle) and it was all good. I now expanded my article to belong to a category and want to do that update there as well. I am not sure if it was the right thing to do but just as a start i hard-coded an update to the ArticleCategory table, just after I do the UpdateModel. This works but I am not sure how to code this update?

I am using the repository patter and i somehow feel that I should be passing an Article and an ArticleCategory object from the view to the controller? While I was writing this I thought that I could just extend my article object to include the categoryID but what if I really wanted to pass two un-related objects from the view to the controller? The UpdateModel persistes the database objects as by VoodooMagic, how would it work if I wanted to update 2 un-related objects?

View 3 Replies







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