MVC :: Entities - Inserting Child Elements From The View?

Feb 27, 2011

I'm trying to create a view that will allow me to create an entity record and also child entities for that record. I have an entity type called "Parent" and I have a child entity called "Child". I want to be able to allow the user to create a Parent including adding several Children and their details, and the npost them all back to the controller from a single view. I found an example on how I would kind of do something like this here: [URL]. The problem with that example is that you can't refer to entities using bracket notation so it only works for those lists. Is there a way to insert hierarchical entity data using MVC from a single view in a single post back?

View 3 Replies


Similar Messages:

ADO.NET :: Generate Id For Set Of Entities When Inserting?

Dec 23, 2010

I have I method where I insert muliple records to a SQL Server 2008 database. The table in which the records are inserted has a primary key integer column with auto increment. The problem is that I have another column called GroupId where I want an integer representing the current insert to be set, i.e. for each time the method gets called a new group id should be generated the group id column of the records to be inserted should be set to this value. What's the best way to generate this group id? I guess I could do a SELECT MAX(GroupId) + 1 FROM Table to generate an id before I make the inserts but this won't be a good solution when it comes to concurrency.

View 13 Replies

ADO.NET :: Inserting Data With LINQ To Entities?

Aug 11, 2010

have already used the latest technology in a professional manner. NETBasically I have two tables related 1 to 1:the Users table and the table ProfiloPersonale is the key to the Users table that this table are ProfiloPersonale iduser and type uniqueidentifier and diagram sql server 2008 I can clearly see the report, I also did a test to insert a record in the users table ( fictional) directly from sql server and everything works.With LINQ to Entities does not work:The entities 'LEntities.Users' part of the eport 'ProfiloPersonale'.Found 'ProfiloPersonale' related to 0.Expected 1 'ProfiloPersonale'Of course what I am doing is to first create the user and then create their profile in the db, taking the id of the registered

View 1 Replies

DataSource Controls :: Inserting Related Entities?

Mar 5, 2010

Inserting Related Entities?

View 14 Replies

MVC :: Inserting Multiples Entities In A Same Transaction With Ef4 In A Project?

Dec 20, 2010

in an mvc controller i need to insert the input data of the user, but that info is splitted in differents entities(differents related tables in the database, but not all tables are related), and i need to insert all info in a same transaction,(so that if one throws an insertion error or another error, undo all the previous changes maded ) how can afford that? or what is the best way to do that?

i am using a project for a repository, just basic data access stuff, a service project that implement my business logic, and my mvc project.

now i am inserting each entity separately, but if any error occurs, all the previous changes to the error still in the db, so with the time i ll have a very dirty db.

View 17 Replies

MVC :: Working With Parent Child Entities?

Sep 22, 2010

i am working on POCO entities. i had a requirement to provide Edit feature for parent and respective Child records in single View.

Eg: Parent-Customer, Child-Order tables

when updating the parent entity by using => UpdateModel(CustomerIns);

and updating the child entity by using => TryUpdateModel(CustomerIns.Order, "Orders");

The Child Controls Names are like Orders[0].OrderID,Oders[0].OrderDate,etc

The Parent and Child Entities are updating when UpdateModel() is called but when saving Changes by calling Context.SaveChanges() i am getting exception like:

"The operation failed: The relationship could not be changed because one or more of the foreign-key properties is non-nullable. When a change is made to a relationship, the related foreign-key property is set to a null value. If the foreign-key does not support null values, a new relationship must be defined, the foreign-key property must be assigned another non-null value, or the unrelated object must be deleted."

View 3 Replies

MVC 2 - Saving Child Entities On Form Submit?

Jun 12, 2010

I'm using ASP.NET MVC 2 and am struggling with saving child entities. I have an existing Invoice entity (which I create on a separate form) and then I have a LogHours view that I'd like to use to save InvoiceLog's, which are child entities of Invoice. Here's the view:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<TothSolutions.Data.Invoice>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Log Hours
</asp:Content>.......

In the SaveHours action, it properly sets the values of the InvoiceLog entities after I call TryUpdateModel but when it does SaveChanges it doesn't update the database with the new values. Also, if you manually update the values of the InvoiceLog entries in the database and then go to this page it doesn't populate the textboxes so it's clearly not binding correctly.

View 1 Replies

C# - NHibernate: Getting Multiple Entities With Subset Of Child Collection?

Jan 16, 2010

My classes look something like this (I include only the relevant properties):

public class Order
{
public virtual Customer Customer { get; set; }
public virtual IEnumerable<OrderLine> OrderLines { get; set; }
}
public class OrderLine
{
public virtual string Product { get; set; } // Simplified
}

Now I What I want is to create a detached criteria that selects all orders for a given customer, and at the same time retrieves only the first 10 OrderLines for each order. The first part is easy:

Customer someCustomerObject = ...; var criteria = DetachedCriteria.For<Order> ).Add(Restrictions.Eq("Customer", someCustomerObject);

But how do I instruct NHibernate to retrieve eagerly the first 10 orderlines for each order retrieved by the criteria above?

I've tried using a Filter based on the following example (taken from Nhibernate documentation):

session.CreateFilter( lazyCollection, "").SetFirstResult(0).SetMaxResults(10).List();

But when I give Order.OrderLines to the CreateFilter method, it retrieves all orderlines first, and then afterwards retrieves the 10 first orderlines, which is not what I want. I also tried combining this with a call to NHibernateUtil.Initialize to no avail.

How do I create a detached criteria for this problem? Or, if that is not entirely possible, how to I retrieve, for each order, the 10 first results only, without fetching the entire collection?

View 1 Replies

Hide Element If It Has No Child Elements?

Jan 8, 2010

I am trying to display elements in a web page using <li>. The structure of the page is as follows

<ul>
<li> (How to hide its visibility if this has no child elements)
<ul>
<li> item 1</li>
<li> item 2</li>
<li> item 3</li>
</ul>
</li>
</ul>

My question is if the li element has no child items how do I hide it. I need to do this dynamically. If I find that I have no records to display as <li> item </li>....I should be able to hide the parent <li>. One soultion is make the <li id="something" runat=server>

if the child elements are not be shown I tried doing childelement.parent.Visible = false.

View 1 Replies

MVC 2 - Name Attributes On HTML Input Field When Using Parent/Child Entities?

Apr 21, 2010

I'm pretty new to MVC 2 using the Entity Framework. I have two tables Company {ID int identity PK,Name nvarchar} and User {ID int identity PK,UserName nvarchar,CompanyID int FK}. A Foreign Key exists between User and Company.I generated my ADO.NET Entity Data Model, a Controller and a view to insert a record. My HTML form has the fields Company and UserName and the is when I click save a Company and User is inserted into the database. Sounds straight forward right!

My question is as follows:

I created a strongly-typed view derived from my 'User' entity. I'm using the the html helper Html.TextBoxFor(model => model.Organisation.Name) but the html name attribute for this input field is 'Organisation.Name'. My problem with this is that the dot throws up all sorts of issues in JQuery, which sees this as a property. If I want to change the name I read that I can use DataAnnotations but because I used the Entity Designer this involves using Buddy Classes. Seems like a bit of overkill just to change the html name attribute on this input field.

View 1 Replies

Applying Events Handler To Child Elements?

Jan 11, 2010

Edit : Problem wasn't related Event Propagation, if you want to know how to stop propagation in jQuery, then use event.stopPropagation();

When user moves his/her mouse over <span> element my jQuery code appends an <img>into this <span> element and when he moves out his mouse off <span> than the element appended is removed. It helps people to edit the field when clicking on the appended <img> element.

The reason I used append() method to add <img> into <span> is because I want to keep <img> element visible when user moves his mouse over to appended <img> element (<img> is becoming <span>'s child element) But it didn't happen and when user moves his mouse over it <img> is being deleted. I am thinking it is because event propagation but I couldn't find how to activate it in jQuery as we do with addEventListener in Firefox based browsers.

JQuery Code :

$(document).ready(function() {
$('.EditEnabled').bind("mouseover", ShowEditFields);
$(".EditEnabled").bind("mouseout", HideEditFields);
});
function ShowEditFields(event) {
$(event.target).append(" <img id='editImg' src='images/edit.png' style='margin-bottom:-3px'/>");
}
function HideEditFields(event) {
$(event.target).children("#editImg").remove();
}

Simple HTML :

<span id="something" class="EditEnabled">Something Here</span>

View 3 Replies

C# - Query The Child Elements Of A Particular Parent Element?

Aug 16, 2010

I am developing asp.net mobile application. I am using the XML as a database. I am using the following part of the XML file to query the data by using the LINQ to XML.

<USER-INTERFACE-DEFINITION>
<MIMICS>
<MIMIC ID="1" NAME="Home">
<SECTIONS>
<SECTION ID ="1" NAME="System Health" CONTROL-TYPE="Button">

[Code]....

In the above XML file I want to retrive the "NAME" attribute of the SECTION node with the condition MIMIC ID="1". I dont want to modify my existing XML file. I have the server collection of node with simialr elements as the above XML file.

View 4 Replies

How To Hide Specific Elements On A Razor View Based On Security Without Logic In View

Apr 4, 2011

I have looked all over for elegant solutions to this not so age-old question. How can I lock down form elements within an ASP.Net MVC View, without adding if...then logic all over the place? Ideally the BaseController, either from OnAuthorization, or OnResultExecultion, would check the rendering form elements and hide/not render them based on role and scope. Another approach I have considered is writing some sort of custom attributes, so as to stay consistent with how how we lock down ActionResults with [Authorize]. Is this even possible without passing a list of hidden objects to the view and putting if's all over? Other background info: We will have a database that will tell us at execution time (based on user role/scope) what elements will be hidden. We are using MVC3 with Razor Viewengine. We're utilizing a BaseController where any of the Controller methods can be overridden.

View 1 Replies

C# - How To Write A Single LINQ To XML Query To Iterate Through All The Child Elements

Aug 14, 2010

I am developing asp.net mobile application. I am using XML as a database. I am querying on the XML to access the required elements & attributes by using LINQ to XML in .net. I have the follwing part in my XML file.

[code]....

The similar logic I need for the above defined XML part. In the above XML I want to write the LINQ to XML query which can access the NAME attribute of the 'VALVE' node (<VALVE NAME="PWV">), then it should access the text between 'DISPLAY-NODE' (<DISPLAY-NAME> Production Master Valve </DISPLAY-NAME>), & then it should access the all the attributes of the 'COMMAND' node dynamically ( <COMMANDS USE-TEMPLATE="TRUE" TEAMPLATE-NAME="ValveCommands.xml"></COMMANDS>). All these I want dynamically without explicitly specifying the name of the child node as well as name of their attributes ( similar to the way I written the above query ) Can we write such a code by using LINQ to XML ? It will be better if we can write code for above issue in a single logic ( similar to the way I written the above query ).

View 1 Replies

AJAX :: Child Elements In LinkButton Break UpdatePanel Functionality, Cause Full Postback

Apr 21, 2010

If I set up a repeater that has LinkButton controls, an UpdatePanel works great. If I add child elements to the LinkButton,such as SPAN, the UpdatePanel stops working as expected. If you click on the area of the LinkButton everything still works, but if you click on the area of the SPAN inside of the LinkButton, you get a full PostBack.I've tried setting ChildrenAsTriggers to true and a few hundred other things. Nothing seems to work. I think the UpdatePanel sees that the "click" event happened on the SPAN and doesn't know to capture it for an async postback.

[code]...

View 4 Replies

Web Forms :: Inserting Code Into Masterpage Tag From Child Page?

Feb 14, 2011

I have a some javascript code that I only want to run in one child page but it needs to be in the head tag to function correctly.

<script type='text/javascript' src=[URL] ></script>
<script type='text/javascript' src=[URL]></script>
<script type='text/javascript' src='lightview/lightview.js'></script>
<link rel="stylesheet" type="text/css" href="lightview/lightview.css" />
end code

Can anyone tell me how to do this? I cannot put it straight into the master page as it conflict with some other javascript code that I am running on a different page! And I cannot put it into the body of the child page because it does not function correctly.

View 4 Replies

C# - Insert A New Row Using A View With Linq To Entities?

Dec 17, 2010

I have a view on my database and I am trying to add a new record using the AddTo method but it is not working. I noticed that LinqToEntities is creating the insert statement like this

Insert into (select field1, field2 from my_view) (field1, field2) values (value1, value2)

Is it possible to make LinqToEntities create the insert statement like the one below ?

Insert into my_view (field1, field2) values (value1, value2)

View 1 Replies

Web Forms :: Add Child Node And Sub Child Node To The Tree View Dynamically

Jan 22, 2011

i want to create one treeview dynamically which will have child node and sub child node.for this i am getting my treeview value from the table with below column:Id,Name,Parent,IsActivewhere main parent nodes parent id will be 0 and then all other records parent id would be related id. the table structure would look

View 3 Replies

MVC :: How To Pass Linq To Entities Query Result To View

Apr 1, 2010

i have a new question: i read all the tutorials that i found but i cannot understand how to pass a result of a linq to entities result to the view so that i can display the results. My query is actually in the controller function ot the view, i would now loop the results and display them in the page. How?

View 23 Replies

Security :: Accessing Elements Within Login View?

Mar 11, 2010

I have the following code for my page:

[Code]....

And the following .cs file associated with it:

[Code]....

I would like to be able to do the following in the .cs file for this page:

#1. Initially "Submit News" is disabled. The admin must click "Preview News" which will update the newslabel temporarily and also enable the "Submit News" button.

#2. When the "Submit News" button is clicked, the news.txt file should be opened and whatever content is currently in the newslabel.Text will be written to news.txt. The news will then be updated for anyone to see.

Right now, if I try to do "submitnews.Enabled = false;" is does not let me because it thinks that submitnews is not in the current context. Basically I need to know how to access elements that are within a <asp:LoginView> area.

View 2 Replies

Hide Non-Displayed ASP Elements In Design View?

Apr 23, 2010

Is there a way to prevent non-displayed elements from appearing in the ASPX Design View editor?By "non-displayed elements", I mean the background elements (Managers, DataSources, Validators, etc) that show up as grey boxes containing the type and id.If I have several of those at the top of the page, I can't see much of the preview of my page.

View 1 Replies

ADO.NET :: EF4 Entities / Create Entities, For Instance, That Only Contains Contact Details Of Client Table?

Nov 16, 2010

I have a datamodel with a couple of tables. One of my tables have about 40 fields (I know that is a lot, but we have to keep the structure in place as we are upgrading a classic ASP project to MVC). Some of my Actions only updates 1 or 2 fields in my table.

Is there a way to create Entities, for instance, that only contains the contact details of the client table, and not any other details, and then another entity that contains only the address details. I don't want to submit the entire row when I only update telephone details, or the client's picture.

View 1 Replies

ADO.NET :: Inserting Data From Details View?

Jan 30, 2011

I have created two tables movie with this columns:[mid], [Mname], [Director], [Genre], [Stars], [Description], [Foto] and table rates with columns: rid, Rate, fkmid. This are in relationship one to many, i added one details view and selected Enabel Inserting because i want to insert in this two tables. Because it is not possible to insert in both tables at the same time i created one view selecting all of the columns from both tables and connected SQLDataSource with this view but still i can't insert data from the Details view to the tables movie and rates because there is relationship between this two tables, i get the following error:

View or function 'ViewRM' is not updatable because the modification affects multiple base tables. Does somebody knows how can i insert data from details view to those two tables?

View 1 Replies

Load Dynamic List Of Elements AFTER FINISHED Loading Of Several Form Elements?

Mar 1, 2010

I have...a dynamic populated select box several input boxes a submit button form fields are loaded initially using cookies several dynamic populated divs

I want... start loading the content of my DIVs after all FORM elements have been loaded completely (= filled with data, select boxes are populated)

Sample code:

[code]....

View 1 Replies

Self Tracking Entities Vs POCO Entities

Sep 28, 2010

We are starting a new web based product in which we are planning to expose our business logic through WCF services. We will be using ASP.NET 4.0, C#, EF 4.0. In future we want to build iphone applications and WPF applications based on the services. I have been reading a lot about using POCO vs Self Tracking Entities (STE) and from my understand the STEs do not work well with the web scenario.

View 3 Replies







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