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
Similar Messages:
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Nov 25, 2010
I have following model class:
public class WebModel
{
public List<ArticleModel> Articles { get; set; }
}
public class ArticleModel
{
public int ID { get; set; }
public double ValueParam { get; set; }
}
Then I have the controller with the two actions:
[Authorize]
public ActionResult Index()
{
WebModel model = new WebModel();
ModelConverter.ConvertToModel(model, controller);
return View(model);
}
[Authorize]
[HttpPost]
[ValidateInput(false)]
public ActionResult Index(WebModel model, string saveButton)
{
ModelValidation.ValidateWebModel(model, ModelState);
if (ModelState.IsValid)
{
return RedirectToAction("Create", "Article");
}
ModelConverter.ConvertToModel(model, controller);
return View(model);
}
And this is my view:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<Web.Models.WebModel>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<%var controller = Session["controller"] as Web.Code.SessionController; %>
<%Html.BeginForm(); %>
<div>
<table width="100%">
<%foreach (var article in Model.Articles)
{%>
<tr style="text-align: right">
<td>
<%:Html.DropDownListFor(m=>m.Articles.FirstOrDefault(f=>f.ID == article.ID).ID, new SelectList(controller.CurrentProdukt.Articles.AsEnumerable(), "ID", "Name", article.ID)) %>
</td>
<td>
<%:Html.TextBoxFor(m => m.Articles.FirstOrDefault(f => f.ID == article.ID).ValueParam)%>
</td>
</tr>
<%} %>
</table>
</div>
<table style="width: 100%">
<tr>
<td>
<input type="submit" name="saveButton" value="Save" />
</td>
</tr>
</table>
<%Html.EndForm(); %>
</asp:Content>
If I press the submit button, I get to the second action method in the controller (the one with the HttpPost attribute). In this action, the object model itself is not null, but the "Articles" list inside is null.
View 2 Replies
Jan 24, 2011
I wonder what you are using when you do the datamodel?Do you write it down on paper or do you use somethin else?Is there any tool I can use in SQL Server 2008?
View 1 Replies
Jun 25, 2010
I am generating links for emails within a class in the model of my MVC site and need to obtain the URL address of the host server the site is running on.
How would I get this?
View 7 Replies
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
May 19, 2010
I'm building an MVC 2 RTM app, and I want to be able to share my model across applications. I'd *like* to be able to implement it like:ASP.NET MVC2 app (holds Views and Controllers)Class library to hold Model(s)WCF app to handle the data transactions with the models via different data stores across apps I had the MVC app working fine, but I wanted to abstract the data stuff and be able to work with the model across apps through the WCF site, so I created a class library project and moved all of the Models classes into that and set-up a WCF app, then added project references to the MVC and WCF apps that point at the class library. The idea was I can create services that take and return objects from the model via method calls across apps. It appears that everything's wired up correctly in the MVC project, so I'm passing the objects stored in the Models class library between controllers and views and everythig is compiling just fine, but for some reason the data is not being passed back from the views to the controller on POST -- all of the properties in the classes are null or empty.
When I debug the app, I can see that the values are stored in the model data dictionary but not the model object itself. What am I doing wrong? Am I on the wrong path, or missing something obvious (to some)?
View 2 Replies
Sep 1, 2010
Is it possible, inside a Custom Model Binder, to fire "something" that "says" the value is invalid so it gets handled by validation part?
Basically, I am getting an exception when the value for the property is invalid.
View 1 Replies
Jan 10, 2011
I made a few changes to the DB in SQL server management studio then right clicked on the .edmx doc to get it to update. That seemed to work fine but when i compiled the app everything that referenced the EF seems to be broken.The Error list now contains the below error for all classes that used it.
The type or namespace name '' could not be found (are you missing a using directive or an assembly reference?)
View 4 Replies