C# - Convert A Model.Tag (has Id And Name) To A "List Of" Name?

Jun 26, 2010

public List<string> TagNameList (int objectId)
{
List<string> tagNameList = db.Tags.Where(ob => ob.Id == objectId).ToList();
}
db.Tags.Where(ob => ob.Id == objectId).ToList();

I'm going into the db context in the Tags and i select all the tags that have a set objectId via a navigation property i have setup through an ObjectTags table that stores the relationships in two columns, both make up a composite key.

The sample returns an IQueryable<app.Models.Tag>. Is there any quick way to convert this to a List<string> with just the Tag.Name?

View 2 Replies


Similar Messages:

MVC :: View Model To Convert To Domain Model?

May 4, 2010

Say I got a domain model as follows: (and my repository expect an instance of this object)

[Code]....

And a view model (which my views are based on)

[Code]....

At the moment I got it like this and have my controller action manually create a new Person object from the PersonModel object before passing it on to the repository, which does not feel right.

So I tried to have PersonModel inherit from Person and pass that to the repository (also tried casting the PersonModel to a Person object first), but that don't work out.

What's the right way to have PersonModel automatically cast to Person? I want to keep this logic as my current structure allow me to keep things really loosely coupled, with the repository layer not having a clue how it's being used.

View 1 Replies

MVC :: How To Pass All The Option List Item From The Drop Down List To View Model

Nov 10, 2010

I have a requirement in my application that, while saving the application, need to get all the value from drop down list and pass it to the view model. But application should not allow the user to select more than one item from drop down list manually, ie, only one value at a time. My view model is like ...

public class ListManagement
{
public IEnumerable<selectListItem> InactiveProduct { get; set; }
public string[] InactiveProductSelected { get; set; }
public IEnumerable<selectListItem> ActiveProduct { get; set; }
}

[code]...

View 3 Replies

How To Convert List<user> To List<object>

May 8, 2010

i have list of user class but now i have to return it as a list of object, i try to convert it but it gives me error like. can not implicitly convert.

View 4 Replies

ADO.NET :: Want Ot Convert This To List Of Type List<Reports>?

Aug 5, 2010

I am executing a Stored procedure from Nhibernate.Below is the sample of my code.

public IList ReportDetails()
{
session.Flush();
ISQLQuery query1 = session.CreateSQLQuery("EXEC dbo.Reports");
System.Collections.IList list = query1.List();
return list;
}

This returns me an Ilist. I want ot convert this to List of Type List<Reports>.Reports class contains all the properties which i will get from Stored Procedure.

View 1 Replies

MVC :: How To Post A List Model

Jan 18, 2011

Customer(Id,Name),
Phone(Id,CustomerId,Number)
Contact(Id,CustomerId,Name,Address)

In My Form

Customer Name : <Textbox>
Phone : <TextBox> <button> : button to Add More <Textbox> Phone to add multiple Phone
Contact Name : <TextBox>
Address : <TextBox> <button> : button to Add More Form Contact add multiple Contact

View 6 Replies

MVC :: Generic List In Model?

Jan 19, 2011

in my model there is a List.

public class InvoiceModel{
public int InvoiceID { get; set; }
public int Date { get; set; }[code]...

for create view i can use Html.TextBoxFor(m => m.InvoiceID) and for Date.but how can i fill List?and how can i use global for this list as Shopping cart?

View 6 Replies

MVC :: List Of Models Inside Another Model?

Dec 30, 2010

I've a product model that contains a list of description models. Every description model contains some string values because every product can have a description for every language. Here it is a semplified version of my models:

[Code]....

So my view to insert a new product is like this:

[Code]....

And my PartialProductDescription view is like this:

[Code]....

Now, the views are perfect. With some Jquery UI I have a form with all the product properties and a tab panel with the language descriptions.

Unfortunatelly my POST action with the firm public ActionResult ProductNew(ProductModel model) has all the model property InternationalDescriptions that contain 2 empty models. So if I write something in the form in the first description textarea, model.InternationalDescrtiptions[0].Description is always empty.

So, how I can tell to MVC to take description textarea values and put them in the model?

View 6 Replies

MVC :: Indicate To The Model Binder That Want To Update The List

Apr 17, 2010

I have a control that's bound to a list property. If I remove elements from that list using javascript and post, then the model gets updated, and the elements get removed.

Unless I remove all the items from the list. Then no names for that property go into the form data, and so the default model binder leaves the model's list untouched. This code from DefaultModelBinder.cs line 572 in the RTM sources makes it clear:

[Code]....

So how do I indicate to the model binder that I do want it to update the list and Ido want the list to be emptied?

View 3 Replies

C# - MVC Dropdown List Isn't Binding To The Model?

Apr 29, 2010

I am trying set up a simple dropdown list but I dont seem to be able to get it to bind to the Model. I am using Asp.Net MVC and nhibernate.

My dropdown list is declared like so:

<%= Html.DropDownListFor(model => model.Project, (IEnumerable<SelectListItem>)ViewData["Projects"], " -- Select -- ", new { name = "Project" })%>

I set up the select list like so:

ViewData["Projects"] = new SelectList(projectRepository.GetAll(), "EntityGUID", "Name", editEntity.Project);

This seems to bind the select list to the Dropdown fine, but the SelectedValue is not set.
it shows up as the default --- Select ---

Also when I save this data, the dropdown does not bind to the model, I have to manually set the object like so to save it:

entity.Project = projectRepository.GetById(new Guid(Request["Project"].ToString()));

I believe I have take the correct messures to have this item bind directly to my model. Is there something I am missing here?

View 2 Replies

MVC :: Bind A Checkbox List To A Model

Feb 3, 2011

I am trying here to find a simple solution to bind an array of elements to a model using the MVC model binder. If I use the @Html.Checkbox helper now, it will generate me something like this :

[Code]....

I should be ok as it manage the checked in state and not checked in. The problem here is when I try to bind it back to the model (something really simple)

[Code]....

In the controller I try to bind it with the UpdateModel()

[Code]....

When I debug, the chk variable in the model is still null. I tried with IList<string>, bool[], IList<bool> nothing seems to make it. Is there any other way to deal with this else than form.GetValues("chk")[0].Contains("true") ?

View 3 Replies

SQL Server :: Adjacency List Model?

Sep 25, 2010

Classic scenario - Categories, Subcategories and Products tables.

Subcategories belong to a corresponding main category

Products belong to a corresponding subcategory

The problem is that not all products do that. Some of them belong directly to a main category because that category has no subcategories. So if I wish to query those products I have to use a main category field in the products table.

And of course I need a subcategory field in the products table also for those products that do belong to a subcategory.

All that does not seem like a good normalized schema.

Now if I use the Adjacency list model the categories and subcategories tables become one (parentID column) and I only have to use a single CatId in my queries.

View 5 Replies

C# - Get List<Model> Object In HTTP POST?

Dec 29, 2010

I have two model classes:

public class UserModel
{
public Guid Id { get; set; }
public string EmailAddress { get; set; }
public string LoginName { get; set; }
public string Password { get; set; }
}
public class GroupModel
{
public Guid Id { get; set; }
public string Name { get; set; }
public List<UserModel> Users { get; set; }
}

I created a View (Create.Aspx) by inheriting GroupModel class.

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<MyApp.Models.GroupModel>" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Create</title>
</head>
<body>
<% using (Html.BeginForm()) {%>
<%: Html.ValidationSummary(true) %>
<fieldset>
<legend>Fields</legend>
<div class="editor-label">
<%: Html.LabelFor(model => model.Id) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.Id) %>
<%: Html.ValidationMessageFor(model => model.Id) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.Name) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.Name) %>
<%: Html.ValidationMessageFor(model => model.Name) %>
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
<% } %>
<div>
<%: Html.ActionLink("Back to List", "Index") %>
</div>
</body>
</html>

It is generating only two fields (Id, Name) in my aspx view. Also I am able to get the form data in the Model class object in Ñ‘[HttpPost]Ñ‘ request which contains the data for ID and NAME field in controller.

[HttpPost]
public ActionResult Create(GroupModel groupModel)
{
try
{
// TODO: Add insert logic here
return RedirectToAction("Index");
}
catch
{
return View();
}
}

How can I get the data in List<UserModel> object? I am thinking to Put a List control with checkboxes containing Users. Then catch them using FormCollection object in controller.

View 1 Replies

C# - Bind List From FormView To Model In Webforms

Mar 5, 2010

For a large fillin form I use the asp.net FormView for the magic databinding to my model. In this model I've a property called Rides (shown below), which exposes a list, which I obviously not want to be replaced entirely. So I made it readonly.

However, this way I can't use the databinding features anymore. Is there a common solution for this problem?

[code]....

View 3 Replies

MVC :: Dynamically Add Items To A List Located In A Model?

Feb 18, 2011

i have a list of complex object let´s say: List<House>, inside of a model that i pass to the view.

To render that list i use the Html.EditorFor(x => x.list[i], "PartialView") inside of a div (<div id="editor"></div>). To "add" an item i use an ajax method that return a new partial view of the same type, an append it to the the div.

This way, the new partial it's appended but when i do the post, only the first item (list[0], the one that i pass in the controller to start) it´s bounded, but, the items added via ajax aren´t.

What could i do in this case? i wan't mi list to grow every time i hit the link that calls the ajax method and then take every item and add them to my database. i've followed this tutorials:

[URL]

[URL]

View 6 Replies

C# - Bind A Checkbox List To A Model Or Array Of Data

Feb 3, 2011

I am looking here to find a quick and easy way to bind a list of checkbox list items when the postback occurs in the model. Apparently the common way to do it now seems to do it like this form.GetValues("checkboxList")[0].Contains("true"); It seems painfull and not exactly safe. Is there a way to bind a list of checkbox (that are created with or without an helper in the view) or even an array of data for that matters during the UpdateModel(myViewModel, form.ToValueProvider()); phase which would populate an IList<string> or string[] inside of the model ?

View 4 Replies

MVC :: Can't Get Razor List View Headings To Use Model Properties

Mar 30, 2011

When it creates a view using the list scaffold the headings are hard coded. I want to pull the headings from the data model, but no luck. I was assuming LabelFor would be the solution. I must be missing something basic.

View 2 Replies

Mvc Model Item Passed In To Dictionary Is Of Type List?

Jul 6, 2010

I have a asp.net mvc view which is strongly typed view and i have a controller which returnsthe ilist user based on the id provided. I am getting the following above error:

The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[Data.User]', but this dictionary requires a model item of type 'Data.User'.

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<Data.User>" %>
<% using (Html.BeginForm())
{%> <%= Html.ValidationSummary(true) %> [code]....

View 3 Replies

MVC :: Show A Model Item As A Drop Down List Or Radiobuttonlist?

Aug 12, 2010

I am working with a model which has the following, basically a Project can have a score between -5 and 5 and I'd like to show a dropdownlist of the available options, i.e 5,4,3,2,1,0,-1,-2,-3,-4,-5.

[Required(ErrorMessage = "Score is required")]
[Range(-5, 5, ErrorMessage = "Score must be between -5 and 5")]
[DisplayName("Score")]
public double Value
{
get { return value; }
set { this.value = value; }
}

What would be the best way to accomplish this using a dropdown list and how can I make the score of 0 the
default selection?

View 3 Replies

MVC :: Pass Model To View - List Truncated After Space?

Aug 16, 2010

I got in the controller action:

var reports = new List<Report>();
reports.Add(new Report {Title = "Inventory (monthly)"});
reports.Add.......

However, the words are truncated when passed to the view.

The words after the space is truncated.

ie. it just passed the word "Inventory".

View 15 Replies

.NET Model-View-Presenter And List Versus Details?

Jan 26, 2010

In Model-View-Presenter what is the correct pattern to do a page that:
a) contains a grid for browsing a list of items

b) an alternate mode for editing single items .maybe you are toggling between two asp:panels.

Do you just make the presenter smart enough to do two types of presentations?
Make 2 presenters?

I'm new to this pattern and want to do it correctly. I understand how I would do this functionality on two pages. Just not sure what is the accepted practice when the browse and detail exist on the same page.

View 1 Replies

Model View Presenter - How To Show Selected Item In A Drop Down List

Jul 23, 2010

I'm using Model-View-Presenter framework. When Loading a page, I'm having trouble setting the selected item that came from the Database.

In view, I know I need:

protected void ddlStatus_SelectedIndexChanged(object sender, EventArgs e)
{
presenter.DdlStatusSelectedIndexChanged();
// what should this pass?
}
Then in Presenter:
public void DdlStatusSelectedIndexChanged()
{
view.DdlStatus = ???
// Should I pass the SelectedIndex?
}

I also think that part of my problem is that DdlStatus I have as a List.

Interface:

List<StatusDTO> DdlStatus { set; get; }

The best I found is here (but needs formatted!) ---> [URL]

View 2 Replies

How To Convert List Into Ienumerable

May 1, 2010

I am using LINQ for data connectivity and have made class which return me the result set into presentation here is the syntax:-

public List<ClsDermaInvestigation> MthdisplayInvestigation()
{
List<ClsDermaInvestigation> lstinvst = new List<ClsDermaInvestigation>();
ISingleResult<USP_Patient_Dermatology_InvestigationResult> investresult = objderma.USP_Patient_Dermatology_Investigation(PatientID, RepDate, Hb, TLC, F);
foreach(USP_Patient_Dermatology_InvestigationResult rel in investresult)
{
ClsDermaInvestigation objinvest = new ClsDermaInvestigation();
objinvest.Albumin = Convert.ToDouble(rel.Albumin);
objinvest.ALP = rel.ALP;
objinvest.ANA = rel.ANA;
objinvest.Date = rel.date;
lstinvest.add(objinvest)}return lstinvest}
This list is returning me the result.It works fine but in 1 case am using the same list to bind my Date dropdownlist.
//aspx.cs code
List<Dermatology.ClsDermaInvestigation> objlstinvest = objinvest.MthdisplayInvestigation();
//Array s = objlstinvest.to
drpDate.DataSource = s;
drpDate.DataTextField = "Repdate";
drpDate.DataValueField = "Repdate";
drpDate.DataBind();

But it throws an error that list does not conatin a property with "Repdate";. How can i bind this list with dropdownlist?? Can i convert it into some type so that i would be able to bind it??

View 2 Replies

ADO.NET :: How To Convert List To Dataset

Mar 8, 2011

I have used the Generic List , so i want to convert the List into dataset, after converting the dataset i have to export the excel in all the details,

how can i convert List to dataset , and also the Export the details.

View 3 Replies

How To Convert List To Datatable

Jul 27, 2010

Possible DuplicateNET - Convert Generic Collection to DataTable
i want to convert list datatype to datatype.
wrote the function

static DataTable ListToDataTable<T>(IEnumerable<T> list)
{
var dt = new DataTable();
foreach (var info in typeof(T).GetProperties())
{
dt.Columns.Add(new DataColumn(info.Name, info.PropertyType));
[code]...

View 2 Replies







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