archive-gr.com » GR » D » DOTNETZONE.GR

Total: 987

Choose link from "Titles, links and description words view":

Or switch to "Titles and links view".
  • Dot Net Rules
    First concurrency CSS css3 data access layer databinding datasets DevExpress disconnected model DNN 7 0 dotnetnuke EF 5 0 Entity framework Entity Framework 6 0 enum support forms authentication general net host wcf HTML HTML 5 html5 IE8 Javascript jquery LINQ LINQ to Entities Linq to Sql LocalDB logging login controls master page master detail membership Mobile Views Model First MS Office objectdatasource performance Polymorphism SEO session state silverlight Sql Server Sql Server 2005 SQL Server 2008 sql server 2012 sqlcommand SQLDataReader stored procedures tables tips and tricks Tracing transaction log transactions UpdatePanel validation VB 2005 VB 2008 VB 9 0 ViewState Visual Basic 10 0 Visual Studio Visual Studio 2005 Visual Studio 2008 Visual Studio 2010 Visual Studio 2012 VS 2010 VS 2012 WCF wcf data service web server controls web service web config window forms windows forms WPF XAML XHTML XML XML Literals Πλοήγηση Αρχική σελίδα Εκδηλώσεις Ιστολόγια Συζητήσεις Εκθέσεις Φωτογραφιών Αρχειοθήκες Ιστορικό Δημοσιεύσεων Ιούνιος 2015 4 Μάρτιος 2015 2 Ιούνιος 2014 1 Δεκέμβριος 2013 2 Νοέμβριος 2013 14 Οκτώβριος 2013 2 Σεπτέμβριος 2013 5 Ιούλιος 2013 1 Ιανουάριος 2013 8 Δεκέμβριος 2012 11 Νοέμβριος 2012 3 Οκτώβριος 2012 12 Σεπτέμβριος 2012 16 Αύγουστος 2012 6 Ιούλιος 2012 13 Ιούνιος 2012 3 Μάιος 2012 4 Απρίλιος 2012 15 Μάρτιος 2012 8 Ιανουάριος 2012 3 Δεκέμβριος 2011 7 Νοέμβριος 2011 13 Οκτώβριος 2011 6 Σεπτέμβριος 2011 8 Αύγουστος 2011 6 Ιούλιος 2011 2 Μάιος 2011 1 Μάρτιος 2011 9 Φεβρουάριος 2011 15 Ιανουάριος 2011 14 Δεκέμβριος 2010 9 Νοέμβριος 2010 2 Οκτώβριος 2010 11 Σεπτέμβριος 2010 1 Αύγουστος 2010 3 Απρίλιος 2010 2 Μάρτιος 2010 5 Ιανουάριος 2010 1 Οκτώβριος 2009 2 Σεπτέμβριος 2009 4 Ιούνιος 2009 5 Απρίλιος 2009 1 Μάρτιος 2009 3 Φεβρουάριος 2009 2 Δεκέμβριος 2008 3 Νοέμβριος 2008 10 Σεπτέμβριος 2008 1 Αύγουστος 2008 1

    Original URL path: http://www.dotnetzone.gr/cs/blogs/dotnetrules/archive/tags/interface/default.aspx (2015-07-15)
    Open archived version from archive


  • Dot Net Rules
    2012 WCF wcf data service web server controls web service web config window forms windows forms WPF XAML XHTML XML XML Literals Πλοήγηση Αρχική σελίδα Εκδηλώσεις Ιστολόγια Συζητήσεις Εκθέσεις Φωτογραφιών Αρχειοθήκες Ιστορικό Δημοσιεύσεων Ιούνιος 2015 4 Μάρτιος 2015 2 Ιούνιος 2014 1 Δεκέμβριος 2013 2 Νοέμβριος 2013 14 Οκτώβριος 2013 2 Σεπτέμβριος 2013 5 Ιούλιος 2013 1 Ιανουάριος 2013 8 Δεκέμβριος 2012 11 Νοέμβριος 2012 3 Οκτώβριος 2012 12 Σεπτέμβριος 2012 16 Αύγουστος 2012 6 Ιούλιος 2012 13 Ιούνιος 2012 3 Μάιος 2012 4 Απρίλιος 2012 15 Μάρτιος 2012 8 Ιανουάριος 2012 3 Δεκέμβριος 2011 7 Νοέμβριος 2011 13 Οκτώβριος 2011 6 Σεπτέμβριος 2011 8 Αύγουστος 2011 6 Ιούλιος 2011 2 Μάιος 2011 1 Μάρτιος 2011 9 Φεβρουάριος 2011 15 Ιανουάριος 2011 14 Δεκέμβριος 2010 9 Νοέμβριος 2010 2 Οκτώβριος 2010 11 Σεπτέμβριος 2010 1 Αύγουστος 2010 3 Απρίλιος 2010 2 Μάρτιος 2010 5 Ιανουάριος 2010 1 Οκτώβριος 2009 2 Σεπτέμβριος 2009 4 Ιούνιος 2009 5 Απρίλιος 2009 1 Μάρτιος 2009 3 Φεβρουάριος 2009 2 Δεκέμβριος 2008 3 Νοέμβριος 2008 10 Σεπτέμβριος 2008 1 Αύγουστος 2008 1 Ιούλιος 2008 9 Ιούνιος 2008 10 Παρουσίαση με Ετικέτες Όλες οι Ετικέτε Javascript RSS animation asp net C clientid CSS css3 html5 IE8 Intellisense jquery modern browsers validation validation controls Visual Studio 2005 Visual Studio 2008 Visual Studio 2010 XHTML Using HTML 5 form input elements in ASP Net applications I am going to start a new series of posts that focus on HTML 5 HTML 5 is something I wanted to learn and finally I have covered enough ground to feel confident HTML 5 gives us things like Semantic tags the possibility to add video and audio in our read more Posted Σάββατο 24 Δεκεμβρίου 2011 3 26 μμ από nikolaosk 0 σχόλια Δημοσίευση στην κατηγορία Javascript asp net html5 modern browsers css3 Creating simple and complex animations with JQuery in ASP Net applications This another post that is focusing on how to use JQuery in our ASP Net applications If you want to have a look at the other posts related to JQuery in my blog click here We always wanted to have eye candy web applications and since the first web pages read more Posted Σάββατο 10 Σεπτεμβρίου 2011 10 42 μμ από nikolaosk 0 σχόλια Δημοσίευση στην κατηγορία Javascript asp net CSS Visual Studio 2010 jquery animation Extending web server controls by providing client side functionality through Javascript In this post I will demonstrate how to extend the functionality of the web server controls by adding client side functionality with Javascript Let s move on to our example 1 Launch Visual Studio 2010 2008 2005 express editions will work fine Create read more Posted Τετάρτη 2 Φεβρουαρίου 2011 7 52 μμ από nikolaosk 0 σχόλια Δημοσίευση στην κατηγορία Visual Studio 2008 Javascript asp net Visual Studio 2005 Visual Studio 2010 clientid ASP Net validation controls In this post I would like to continue talking about validation in ASP Net applications I will look into the validation controls that ASP

    Original URL path: http://www.dotnetzone.gr/cs/blogs/dotnetrules/archive/tags/Javascript/default.aspx (2015-07-15)
    Open archived version from archive

  • Dot Net Rules
    generated for the Delete method in the ReviewsController cs GET Reviews Delete 5 public ActionResult Delete int id MovieReview moviereview db Reviews Find id if moviereview null return HttpNotFound return View moviereview POST Reviews Delete 5 HttpPost ActionName Delete public ActionResult DeleteConfirmed int id MovieReview moviereview db Reviews Find id db Reviews Remove moviereview db SaveChanges return RedirectToAction Index new id moviereview MovieId This method will post back the form to the same url it came from Now we build and run the application again When I click on the Movie link http localhost 59871 Movie in the menu I see the Reviews link for both my movies I choose to click on the Reviews link for the first movie The GodFather and when I click on it I can see the reviews and hit the Delete link Have a look at the picture below Finally I hit the Delete button and my review for that movie has been deleted Do not underestimate what we have accomplished so far We have managed to develop an ASP Net MVC 4 0 application where one can create edit delete view and search for movies He can also create edit delete view reviews for a particular movie In the next post I will talk about validation through data annotations and database migrations within the context of the Entity Framework Code First Paradigm Hope it helps Posted Τρίτη 1 Ιανουαρίου 2013 5 19 μμ από nikolaosk 0 σχόλια Δημοσίευση στην κατηγορία asp net C CSS Entity framework jquery HTML Code First Visual Studio 2012 ASP NET MVC 4 0 Creating a complete ASP Net MVC 4 0 application with Visual Studio 2012 C EF 5 0 Code First part 4 I have decided to write a series of posts on how to write a small ASP Net MVC 4 0 application I will develop this application step by step and I will explain everything that you need to know in order to develop ASP Net MVC 4 0 applications This is the fourth post in this series You can find the first one here the second one here and the third one here Make sure you read and understand those posts I am building an ASP Net MVC application where users can enter movies and rate them As we develop our application I will change the requirements and add more features My goal is to have a working application and at the same time show you the building blocks of ASP Net MVC In the last post we have created the entities needed in order to store and retrieve data models views and the database Now I would like to talk about Code Blocks and Code Expressions in Razor Views 1 Launch Visual Studio and open the ASP Net MVC application 2 Open the Index cshtml from the Views Movie folder These are the contents of the view model IEnumerable MovieReviews Models Μovie ViewBag Title Index h2 Index h2 p Html ActionLink Create New Create p table tr th Html DisplayNameFor model model Name th th Html DisplayNameFor model model Director th th Html DisplayNameFor model model YearReleased th th th tr foreach var item in Model tr td Html DisplayFor modelItem item Name td td Html DisplayFor modelItem item Director td td Html DisplayFor modelItem item YearReleased td td Html ActionLink Edit Edit new id item Id Html ActionLink Details Details new id item Id Html ActionLink Delete Delete new id item Id td tr table The responsibility of this view is to take the model passed by the controller and present the data to the users through the template The View is nothing more than a template where the data passed from the model is presented We combine literal text e g h2 h2 with pieces of data from the model through C code Code Expressions An example of code expressions from the view above td Html DisplayFor modelItem item Name td The code in bold is a code expression The code expression will be evaluated by the Razor engine and the output which will be displayed in a column of an html table will be presented to the client Code blocks An example of code block from the view above ViewBag Title Index Between the curly braces we can add as much C code as we want Let me modify a little bit the View above ViewBag Title Index var reviewscount Model Count h2 Index h2 h3 the number of the reviews so far is reviewscount h3 The code I changed is in bold Run your application again http localhost 59871 movie http localhost yourport movie in your case I added a new variable inside the code block and then used the variable reviewscount in a place I wanted inside the view as a code expression Hope all makes sense so far 3 Now I would like to point out at this point are HTML Helpers that are part of any View in the ASP Net MVC applications Their purpose is to create small blocks of HTML There are helpers like to create links inputs labels forms validation messages and much more Think of them like traditional ASP NET Web Form controls We use HTML helpers are used to modify HTML HTML helpers do not have an event model and a view state In most cases an HTML helper is just a method that returns a string Let s have a look at the Html ActionLink Html ActionLink Edit Edit new id item Id This is the easiest way to render an HTML link The Html ActionLink does not link to a view It creates a link to a controller action You also can see more HTML Helpers in the View Html DisplayNameFor which Gets the display name for the model Html DisplayFor will render the DisplayTemplate that matches the property s type There are more HTML helpers can be used to render modify and output HTML form elements BeginForm EndForm TextArea TextBox ValidationMessageFor We will see more of those as we move on 3 When you run your application and navigate to the http localhost 59871 movie you see HTML elements that are not in the current view Index view I mean the navigation system menu the header logo and the footer Where does this markup come from It comes form the Layout View Υοu can think of this as the master pages in web forms applications Have a look at the picture below to see what I mean Have a look in the Shared folder in the Solution Explorer You will see the Layout cshtml DOCTYPE html html lang en head meta charset utf 8 title ViewBag Title My ASP NET MVC Application title link href favicon ico rel shortcut icon type image x icon meta name viewport content width device width Styles Render Content css Scripts Render bundles modernizr head body header div class content wrapper div class float left p class site title Html ActionLink your logo here Index Home p div div class float right section id login Html Partial LoginPartial section nav ul id menu li Html ActionLink Home Index Home li li Html ActionLink About About Home li li Html ActionLink Contact Contact Home li ul nav div div header div id body RenderSection featured required false section class content wrapper main content clear fix RenderBody section div footer div class content wrapper div class float left p copy DateTime Now Year My ASP NET MVC Application p div div footer Scripts Render bundles jquery RenderSection scripts required false body html We have the head section that will be present in all pages head meta charset utf 8 title ViewBag Title My ASP NET MVC Application title link href favicon ico rel shortcut icon type image x icon meta name viewport content width device width Styles Render Content css Scripts Render bundles modernizr head Then you have the header section that will appear in all pages header div class content wrapper div class float left p class site title Html ActionLink your logo here Index Home p div div class float right section id login Html Partial LoginPartial section nav ul id menu li Html ActionLink Home Index Home li li Html ActionLink About About Home li li Html ActionLink Contact Contact Home li ul nav div div header Then you have the header section that will appear in all pages footer div class content wrapper div class float left p copy DateTime Now Year My ASP NET MVC Application p div div footer At one point we see a call to the RenderBody div id body RenderSection featured required false section class content wrapper main content clear fix RenderBody section When the Layout View calls RenderBody that is when the content View index cshtml will be inserted and rendered at this exact point in the HTML markup How does ASP Net MVC to call the Layout View before our content View It is because of this file ViewStart cshtml The contents of the ViewStart cshtml follow Layout Views Shared Layout cshtml ASP Net MVC runtime knows to render first the Layout View because the ViewStart cshtml runs first before any other view and then the Content View 4 Another important topic in ASP Net MVC applications are Partial Views At some point in the Layout cshtml view there is a call to the LoginPartial partial view section id login Html Partial LoginPartial section A partial view is a view that we place code HTML C that we will often reuse in other views Have a look at the contents of the LoginPartial cshtml if Request IsAuthenticated text Hello Html ActionLink User Identity Name Manage Account routeValues null htmlAttributes new class username title Manage using Html BeginForm LogOff Account FormMethod Post new id logoutForm Html AntiForgeryToken a href BLOCKED SCRIPTdocument getElementById logoutForm submit Log off a text else ul li Html ActionLink Register Register Account routeValues null htmlAttributes new id registerLink li li Html ActionLink Log in Login Account routeValues null htmlAttributes new id loginLink li ul So this is a type of special View that we must know and use so we make our application easier to maintain 5 Now it is time to have a look at some important topics that are related with Controllers Open the MovieController cs file I would like to talk a bit about ActionResults and what thet are The ActionResult is an abstract base class for other types of actions Other classes inheriting from the ActionResult ContentResult EmptyResult FileResult HttpStatusCodeResult JavaScriptResult RedirectResult RedirectToRouteResult ViewResult The ViewResult renders a specifed view to the client The RedirectResult performs an HTTP redirection to a specified URL The ContentResult writes content to the client without requiring a view In this method Index the result of this method is ActionResult which means we will call the Index cshtml passing the model to it in the Views Movie folder So the results of this view will be displayed to the client private MovieDBContext db new MovieDBContext GET Movie public ActionResult Index return View db Movies ToList Another very important topic is Action Selectors Some of them are ActionName AcceptVerbs An ActionSelector dictates which action method is triggered They come with the form of attributes Have a look at the MovieController cs file and the Delete method HttpPost ActionName Delete public ActionResult DeleteConfirmed int id Μovie μovie db Movies Find id db Movies Remove μovie db SaveChanges return RedirectToAction Index ActionName will specify the name of this method It can be reached by Delete and not DeleteConfirmed AcceptVerbs HttpPost HttpGet represent attributes that specify which HTTP verbs Get Post an action method will respond to In the example above we have an HTTP Post HttpPost ActionName Delete The final topic I would like to talk about is Action Filters They are applied to methods and classes in the form of attributes An ActionFilter provides some methods that are run before and after request and response processing Some of them are OutputCache which caches the output of the controller Authorize that restricts an action to authorized users or roles If I open the MovieController cs file and then apply the Authorize see below to the Index method private MovieDBContext db new MovieDBContext GET Movie Authorize public ActionResult Index return View db Movies ToList and then navigate to the http localhost 59871 movie this is what I will get the following as a result redirect to the login page The ASP Net MVC runtime will pick up the Authorize attribute and redirect me to the Login page Hope you have followed along and mastered the topics presented here as they are absolutely necessary for building ASP Net MVC applications In the next post we will continue building our application Hope it helps Posted Κυριακή 30 Δεκεμβρίου 2012 11 37 μμ από nikolaosk 0 σχόλια Δημοσίευση στην κατηγορία asp net C CSS Entity framework jquery HTML Code First Visual Studio 2012 ASP NET MVC 4 0 Creating a complete ASP Net MVC 4 0 application with Visual Studio 2012 C EF 5 0 Code First part 3 I have decided to write a series of posts on how to write a small ASP Net MVC 4 0 application I will develop this application step by step and I will explain everything that you need to know in order to develop ASP Net MVC 4 0 applications This is the third post in this series You can find the first one here and the second one here Make sure you read and understand the first post and the second post As I design and develop the application I will explain some of the most common building blocks of ASP Net MVC like Code blocks Code expressions Action Results Action Selectors Action Filters Layout Views and Partial Views Now we have to think about the data access technology that we will use in our sample application I am going to build an ASP Net MVC application where users can search through a collection of movies and rate them I will not use traditional ADO Net data access techniques I will use Entity Framework EF which is part of the Net framework Obviously I cannot go into much detail on what EF is and what it does I will give again a short introduction The Net framework provides support for Object Relational Mapping through EF So EF is a an ORM tool and it is now the main data access technology that microsoft works on I use it quite extensively in my projects Through EF we have many things out of the box provided for us We have the automatic generation of SQL code It maps relational data to strongly types objects All the changes made to the objects in the memory are persisted in a transactional way back to the data store You can search in my blog because I have posted many posts regarding ASP Net and EF There are different approaches paradigms available using the Entity Framework namely Database First Code First Model First You can find in this post an example on how to use the Entity Framework to retrieve data from an SQL Server Database using the Database Schema First approach In this approach we make all the changes at the database level and then we update the model with those changes In this post you can see an example on how to use the Model First approach when working with ASP Net and the Entity Framework This model was firstly introduced in EF version 4 0 and we could start with a blank model and then create a database from that model When we made changes to the model we could recreate the database from the new model The Code First approach is the more code centric than the other two Basically we write POCO classes and then we persist to a database using something called DBContext In this application we will us the Code First approach when building our data centric application with EF Code First relies on DbContext We create 2 3 classes e g Movie Review with properties and then these classes interact with the DbContext class Then we can create a new database based upon our POCOS classes and have tables generated from those classes We do not have an edmx file in this approach By using this approach we can write much easier unit tests DbContext is a new context class and is smaller lightweight wrapper for the main context class which is ObjectContext Schema First and Model First When building an application the most important thing is to understand the domain and the domain business objects These should be the objects that should drive the application and not e g the database schema So I like to design my entities very carefully and 1 Launch Visual Studio and open your application 2 We will add the 2 entities I am going to show you below in the Models folder Add a new class file named Movie cs inside the Models folder The Movie cs entity is as follows public class Μovie public int Id get set public string Name get set public string Director get set public DateTime YearReleased get set public ICollection MovieReview Reviews get set We have added some properties in this entity Now we need to add the MovieReview entity Add a new class file named MovieReview cs inside the Models folder The MovieReview cs entity is as follows public class MovieReview public int Id get set public int Rating get set public string Comment get set public int MovieId get set So we have our entities ready We have one movie and many reviews That should be clear by now I will instantiate these objects store them and retrieve them in my database My database will be an SQL Server database where I will create from the entities Then we need to create a context class that inherits from DbContext Add a new class to the Models folder Name it MovieDBContext cs Now that we have the entity classes created we must let the model know I will have to use the DbSet T property The code for this class follows public class MovieDBContext DbContext public DbSet Μovie Movies get set public DbSet MovieReview Reviews get set The MovieDBContext is a database context class This class is responsible for talking to the underlying database storing and updating the data to the database We need to add this reference to the file using System Data Entity Now we need to create the connection string The only place we can do that is by opening the web config file and adding the following lines of code inside the connectionStrings section connectionStrings add name FootballerDBContext connectionString Data Source LocalDb v11 0 AttachDbFilename DataDirectory MovieReviews mdf Integrated Security True providerName System Data SqlClient connectionStrings 3 Now we need to access our model from a controller This is going to be a simple class that retrieves the footballers data Right click the Controllers folder and create a new MovieController controller Have a look at the picture below to set the appropriate settings and then click Add Visual Studio will create the following A MovieController cs file in the project s Controllers folder A Movie folder in the project s Views folder Create cshtml Delete cshtml Details cshtml Edit cshtml and Index cshtml in the new Views Footballer folder Have a look at the picture below The ASP NET MVC 4 framework automatically creates the CRUD create read update and delete action methods and views This is know as scaffolding We have a fully functional web application that lets you create list edit and delete records 4 Build and run your application Navigate to the localhost youport movie Have a look at the picture below I will create two entries for two of my favorite movies The Godfather Raging Bull I click on the Create New link and insert the data Finally I click Create The data is saved in the database I know exactly what you are thinking right now You did not create any database Entity Framework Code First created the database for us EF detected that the database connection string provided pointing to a database didn t exist so Code First created the database automatically Have a look at the picture below Make sure you add your entries to the database through the view We have created two new records and stored it in the database Click the Edit Details and Delete links We have all this functionality out of the box through the magic of scaffolding I urge you to have a look place breakpoints as well in the MovieController cs class file and notice the flow of the execution We pass a strongly typed object Movie to the various views Have a look again in the views inside the Views Movie folder In the Create cshtml Delete cshtml Details cshtml Edit cshtml and Index cshtml Views at the beginning of these files you will see this line of code model MovieReviews Models Μovie By adding a model statement at the top of the view file we tell the view the type of object that the view should rende r This is how we pass a model through a controller to the appropriate view I am sure you can clearly see the separation of concerns 5 Now we can see our database and the data that was saved We go to View Server Explorer or Database Explorer and connect to the instance of SQL Server Have a a look at the picture below to see what I mean Click OK Have a look at the picture below to see the database and the tables Now I can see the data that was inserted through my ASP Net MVC application to the database I am sure you know have a feeling about the application we are about to build I will explain more about ASP Net MVC as we go on building the application Hope it helps Posted Κυριακή 30 Δεκεμβρίου 2012 5 35 μμ από nikolaosk 0 σχόλια Δημοσίευση στην κατηγορία asp net C CSS Entity framework jquery HTML Code First Visual Studio 2012 ASP NET MVC 4 0 Creating a complete ASP Net MVC 4 0 application with Visual Studio 2012 C EF 5 0 Code First part 2 I have decided to write a series of posts on how to write a small ASP Net MVC 4 0 application I will develop this application step by step and I will explain everything that you need to know in order to develop ASP Net MVC 4 0 applications This is the second posts in this series You can find the first one here Make sure you read and understand the first post In this post I would like to look into the internals of ASP Net MVC and what happens when an incoming HTTP request comes in from the browser Bear in mind that the local web server is IIS Express This is the web server that will handle the incoming request IIS Express will take that request and deliver it to my application Let s run our application again and click on the Contact link on the top right hand corner of the page When I click that link the URL in my browser becomes http localhost 59871 Home Contact As mentioned earlier the local web server will take this request and deliver it to my ASP Net MVC application Inside the ASP Net MVC application there is a Routing Engine that takes requests and delivers them to the proper component In this case the request will end up in the HomeController cs class file Remember that the Controller is the component in the MVC pattern that orchestrates everything A request for Home Something will always come to the HomeController cs class A request in our case http localhost 59871 Home Contact will end up in the Contact method inside the HomeController cs class file Have a look at the picture below I am sure you can see the naming conventions applied here This action method public ActionResult Contact does not do anything else but to return a View No Model is build on this occasion So how can we reach the appropriate view to display There are more naming conventions Τhe ASP Net MVC application will look in the Views Folder and then in the Home folder The name Home matches the name of the Home controller and then it will pick the Contact cshtml Inside this view there is all the markup that is rendered by the browser Have a look at the picture below I would like to explain a bit more the ViewBag property The ViewBag allows data to be added to it which is then available in the View It is similar to how a session variable works when you assign a value to a ViewBag property such as ViewBag Have a look at the HomeController cs file and the Contact method It passes the ViewBag Message Your contact page to the Contact View Open the Contact cshtml file in the Solution Explorer hgroup class title h1 ViewBag Title h1 h2 ViewBag Message h2 hgroup As you can see in the bold line above this is the way we get the contents of the ViewBag Message in the our view Let s add another ViewBag property Have a look at the code below public ActionResult Contact ViewBag Message Your contact page ViewBag AdminEmail admin example com return View I have added ViewBag AdminEmail to the Contact method Now I am going to retrieve the value inside the ViewBag AdminEmail from the Contact cshtml view p span class label WebMaster span span a href mailto ViewBag AdminEmail ViewBag AdminEmail a span p Obviously this is not the best way to pass data from our controller to the View Let s add a model to our application In the Models folder add a new class file and name it ContactModel cs The contents of this class follow namespace MovieReviews Models public class ContactModel public string Name get set public string Surname get set public string Email get set I add three properties in my class Now I need to change the code inside the Contact method in the HomeController cs class This is how Contact method looks now public ActionResult Contact ViewBag Message Your contact page ViewBag AdminEmail admin example com var contact new ContactModel contact Name Nick contact Surname kantzelis contact Email nikolaosk admin com return View contact With this line of code return View contact we say that we want to pass this model contact to the appropriate View We need to modify the Contact cshtml view p span class label Name Model Name span br span class label Surname Model Surname span br span class label Email Model Email span p We use the Model property represents the model object ContactModel object passed to the view This is a strongly typed property as opposed to the ViewBag In the beginning of the Contact cshtml we must add this line of code model MovieReviews Models ContactModel By this line of code I inform the View about the model and what kind of model ContactModel object it has The razor engine now knows how to display this information to the user We just have to place the Model property in the appropriate place in the View Now when I run the application I see the following results Hope all makes sense now I mean how the MVC pattern works and what the Controller Model and the View do I know that we have not build the actual application yet We will do that step by step in the next posts but it is of vital significance to understand the basic components of the MVC pattern and its internals Hope it helps Posted Σάββατο 29 Δεκεμβρίου 2012 3 31 μμ από nikolaosk 0 σχόλια Δημοσίευση στην κατηγορία asp net C CSS Entity framework jquery HTML Code First Visual Studio 2012 ASP NET MVC 4 0 Creating a complete ASP Net MVC 4 0 application with Visual Studio 2012 C EF 5 0 Code First part 1 I have been using ASP Net MVC Visual Studio C Entity Framework JQuery CSS to build web sites and applications I have been teaching ASP Net MVC to people from all walks of life with different experience in Web development I have decided to write a series of posts on how to write a small ASP Net MVC 4 0 application I will develop this application step by step and I will explain everything that you need to know in order to develop ASP Net MVC 4 0 applications There are some other posts in my blog regarding ASP Net MVC You can find them here here Please have a look at those posts to get a feeling for ASP Net MVC I will repeat some of the content found in those posts in the posts that will be part of this series If you are an experienced ASP NET MVC developer maybe you mus go on and read something more advanced I will talk about advanced things later on though This series is aimed at developers that start learning ASP Net MVC I assume that you have some working knowledge of HTML CSS It will be great if you programmed before with C or used Visual Studio Αs I said earlier I will try to explain everything in detail so beginners can benefit from that I am going to build a web application where users can post reviews about movies The user can list the reviews edit the reviews and obviously create a review The administrator will be able to post movies so other users can review it Users can also search for movies to review This is the general overview of the application I will explain more about the application as we move on I will also show you how to deploy the application to IIS and Windows Azure towards the end The most important thing right now is to download and install all the tools libary software in your computer so you can follow along You can download all the necessary software tools Visual Studio 2012 Web Edition along with a web server a Sql Server instance libraries binaries if you download Web Platform Installer You can download this tool from this link After you install it you must search for Visual Studio Express 2012 for Web Have a look at the picture below Then click Add and then Install Everything you need will be installed Maybe you need to reboot the machine so do not worry if you will have to do this So now you have an IDE Visual Studio 2012 that you can write test and debug your code SQL Server is also installed We need SQL Server to persist our data back to the database A lightweight web server IIS Express is also installed so it can execute host our web application our code during development I have installed Visual Studio 2012 Ultimate edition in my machine which is Windows 8 by the way I have also installed the latest version of Net Framework and I will show you later how to download more libraries when needed I have installed SQL Server 2012 Enterprise Edition in my machine As a Microsoft Certified Trainer I have access to this software but as explained earlier you need only to download Web Platform Installer and then download the Visual Studio Express 2012 for Web and install it Before we move on to the actual hands on demo I would like to say a few words on how I understand ASP Net MVC and what its main benefits design goals are Obviously the first paradigm on bulding web applications on the web is Web Forms Web forms was the first and only way to build web application when ASP Net was introduced to the world ten years ago It replaced the classic ASP model by providing us with a strongly typed code that replaced scripting We had have languages that are compiled Web forms feels like a form that you programmed with VB 6 0 for the desktop The main idea was to abstract the WEB By that I mean HTML is abstracted in a way Click events replaced Post operations Since that time web standards have strengthened and client side programming is on the rise Developers wanted to have more control on the HTML Web forms as I said before handles HTML in an abstract way and is not the best paradigm for allowing full control on the HTML rendering ASP Net MVC provide us with a new way of writing ASP Net applications It does not replace Web Forms It is just an alternative project type It still runs on ASP Net and supports caching sesions and master pages In ASP Net MVC applications we have no viewstate or page lifecycle For more information on understanding the MVC application execution process have a look at this link It is a highly extensible and testable model In order to see what features of ASP Net are compatible in both Models have a look here MVC pattern has been around for decades and it has been used across many technologies as a design pattern to use when building UI It is based on an architecture model that embraces the so called seperation of concern pattern There are three main building blocks in the MVC pattern The View talks to the Model The Model has the data that the View needs to display The View does not have much logic in them at all The Controller orchestrates everything When we have an HTTP request coming in that request is routed to the Controller It is up to the Controller to talk to the file system database and build the mode l The routing mechanism in MVC is implemented through the System Web Routing assembly Routes are defined during application startup Have a look at the Global asax file when building an MVC application The Controller will select which View to use to display the Model to the client It is clear that we have now a model that fully supports seperation of concerns The Controller is responsible for building the Model and selecting the View The Controller does not save any data or state The Model is responsible for that The Controller selects the View but has nothing to do with displaying data to the client This is the View s job The Controller component is basically a class file that we can write VB Net or C code We do not have Page Load event handler routines just simple methods which are easy to test No code behind files are associated with the Controller classes All these classes should be under the Controllers folder in your application Controller type name must end with Controller e g ProductController In the Views folder we should place the files responsible for displaying content to the client Create subfolders for every Controller Shared folder contains views used by multiple controllers In this post I will use the Razor View engine rather than the WebForms View Razor View engine is designed with MVC in mind and it is the way as far as I am concerned to work with ASP Net MVC ASP Net MVC does not dictate what kind of data access architecture we will use in our application It does not also dictate how to build our business layer domain classes and objects Finally ASP Net MVC is very extensible and easy to test Let s start building our web application 1 I am launching VS 2012 and I will Visual C as the programming

    Original URL path: http://www.dotnetzone.gr/cs/blogs/dotnetrules/archive/tags/jquery/default.aspx (2015-07-15)
    Open archived version from archive

  • Dot Net Rules
    forms authentication general net host wcf HTML HTML 5 html5 IE8 interface Javascript jquery Lambdas lazy loading LINQ LINQ to Entities LINQ to objects Linq to Sql LocalDB Localisation performance POCOS Polymorphism routing scaffolding ScriptManager SEO session state silverlight Sql Server Sql Server 2005 SQL Server 2008 sql server 2012 sqlcommand SQLDataReader stored procedures tables tips and tricks Tracing transaction log transactions UpdatePanel validation VB 2005 VB 2008 VB 9 0 ViewState Visual Basic 10 0 Visual Studio Visual Studio 2005 Visual Studio 2008 Visual Studio 2010 Visual Studio 2012 VS 2010 VS 2012 WCF wcf data service web server controls web service web config window forms windows forms WPF XAML XHTML XML XML Literals Πλοήγηση Αρχική σελίδα Εκδηλώσεις Ιστολόγια Συζητήσεις Εκθέσεις Φωτογραφιών Αρχειοθήκες Ιστορικό Δημοσιεύσεων Ιούνιος 2015 4 Μάρτιος 2015 2 Ιούνιος 2014 1 Δεκέμβριος 2013 2 Νοέμβριος 2013 14 Οκτώβριος 2013 2 Σεπτέμβριος 2013 5 Ιούλιος 2013 1 Ιανουάριος 2013 8 Δεκέμβριος 2012 11 Νοέμβριος 2012 3 Οκτώβριος 2012 12 Σεπτέμβριος 2012 16 Αύγουστος 2012 6 Ιούλιος 2012 13 Ιούνιος 2012 3 Μάιος 2012 4 Απρίλιος 2012 15 Μάρτιος 2012 8 Ιανουάριος 2012 3 Δεκέμβριος 2011 7 Νοέμβριος 2011 13 Οκτώβριος 2011 6 Σεπτέμβριος 2011 8 Αύγουστος 2011 6 Ιούλιος 2011 2 Μάιος 2011 1 Μάρτιος 2011 9 Φεβρουάριος 2011 15 Ιανουάριος 2011 14 Δεκέμβριος 2010 9 Νοέμβριος 2010 2 Οκτώβριος 2010 11 Σεπτέμβριος 2010 1 Αύγουστος 2010 3 Απρίλιος 2010 2 Μάρτιος 2010 5 Ιανουάριος 2010 1 Οκτώβριος 2009 2 Σεπτέμβριος 2009 4 Ιούνιος 2009 5 Απρίλιος 2009 1 Μάρτιος 2009 3 Φεβρουάριος 2009 2 Δεκέμβριος 2008 3 Νοέμβριος 2008 10 Σεπτέμβριος 2008 1 Αύγουστος 2008 1 Ιούλιος 2008 9 Ιούνιος 2008 10 Παρουσίαση με Ετικέτες Όλες οι Ετικέτε Lambdas RSS asp net C c 3 0 LINQ linq query syntax LINQ to objects Visual Studio 2008

    Original URL path: http://www.dotnetzone.gr/cs/blogs/dotnetrules/archive/tags/Lambdas/default.aspx (2015-07-15)
    Open archived version from archive

  • Dot Net Rules
    Φεβρουάριος 2011 15 Ιανουάριος 2011 14 Δεκέμβριος 2010 9 Νοέμβριος 2010 2 Οκτώβριος 2010 11 Σεπτέμβριος 2010 1 Αύγουστος 2010 3 Απρίλιος 2010 2 Μάρτιος 2010 5 Ιανουάριος 2010 1 Οκτώβριος 2009 2 Σεπτέμβριος 2009 4 Ιούνιος 2009 5 Απρίλιος 2009 1 Μάρτιος 2009 3 Φεβρουάριος 2009 2 Δεκέμβριος 2008 3 Νοέμβριος 2008 10 Σεπτέμβριος 2008 1 Αύγουστος 2008 1 Ιούλιος 2008 9 Ιούνιος 2008 10 Παρουσίαση με Ετικέτες Όλες οι Ετικέτε LINQ RSS NET NET 3 5 Framework anonymous types asp net C c 3 0 C 3 0 Excel extension methods general net Lambdas linq query syntax LINQ to objects Linq to Sql MS Office SQL Server 2008 VB 9 0 Visual Studio 2008 Visual Studio 2010 XML XML Literals An abundance of LINQ queries and expressions using both the query and method syntax In this post I will be writing LINQ queries against an array of strings an array of integers Moreover I will be using LINQ to query an SQL Server database I can use LINQ against arrays since the array of strings integers implement the IENumerable interface read more Posted Πέμπτη 27 Ιανουαρίου 2011 12 37 μμ από nikolaosk 0 σχόλια Δημοσίευση στην κατηγορία Visual Studio 2008 LINQ asp net C Visual Studio 2010 LINQ to objects Lambdas linq query syntax Linq to Objects in ASP Net In this post I would like to talk about Linq to Objects in an ASP Net application In all my classes people seem to have the following answer to this question What kind of data can we query with LINQ Most people say Well we can query an SQL server database I am not very Διαβάστε περισσότερα Posted Τετάρτη 6 Οκτωβρίου 2010 1 58 πμ από nikolaosk 0 σχόλια Δημοσίευση στην κατηγορία Visual Studio 2008 LINQ asp net C Visual Studio 2010 LINQ to objects Create an XML file using LINQ and import XML data into an Excel spreadsheet In this post I will try to create an excel file and populate the rows and columns with XML data that I read from a relational database table I will use Visual Studio 2008 vb and in particular XML Literals and LINQ to SQL classes Διαβάστε περισσότερα Posted Τρίτη 31 Μαρτίου 2009 10 39 μμ από nikolaosk 0 σχόλια Δημοσίευση στην κατηγορία Visual Studio 2008 XML VB 9 0 Excel XML Literals LINQ MS Office Linq to Sql LINQ TO SQL and Stored procedures In this post I will go back to the issue of LINQ I am going to show with an example how to use LINQ and stored procedures to insert update and delete records from a particular table Διαβάστε περισσότερα Posted Σάββατο 13 Δεκεμβρίου 2008 6 17 μμ από nikolaosk 0 σχόλια Δημοσίευση στην κατηγορία Visual Studio 2008 LINQ Linq to Sql SQL Server 2008 C 3 0 NET 3 5 Framework c 3 0 How to monitor and debug LINQ to SQL queries How to monitor and debug LINQ to SQL queries Διαβάστε περισσότερα Posted

    Original URL path: http://www.dotnetzone.gr/cs/blogs/dotnetrules/archive/tags/LINQ/default.aspx (2015-07-15)
    Open archived version from archive

  • Dot Net Rules
    4 5 Web Forms store that sells posters on line There are 3 more posts in this series of posts Please make sure you read them first You can find the first post here You can find the second post here You can find the third post here In this new post we will build on the previous posts and we will demonstrate how to display the posters per category We will add a ListView control on the PosterList aspx and will bind data from the database We will use the various templates Then we will write code in the PosterList aspx cs to fetch data from the database 1 Launch Visual Studio and open your solution where your project lives 2 Open the PosterList aspx page We will add some markup in this page Have a look at the code below section class posters featured ul asp ListView ID posterList runat server DataKeyNames PosterID GroupItemCount 3 ItemType PostersOnLine DAL Poster SelectMethod GetPosters EmptyDataTemplate table id Table1 runat server tr td We have no data td tr table EmptyDataTemplate EmptyItemTemplate td id Td1 runat server EmptyItemTemplate GroupTemplate tr ID itemPlaceholderContainer runat server td ID itemPlaceholder runat server td tr GroupTemplate ItemTemplate td id Td2 runat server table tr td nbsp td td a href PosterDetails aspx posterID Item PosterID img src Item PosterImgpath width 100 height 75 border 1 a td td a href PosterDetails aspx posterID Item PosterID span class PosterName Item PosterName span a br span class PosterPrice b Price b String Format 0 c Item PosterPrice span br td tr table td ItemTemplate LayoutTemplate table id Table2 runat server tr id Tr1 runat server td id Td3 runat server table ID groupPlaceholderContainer runat server tr ID groupPlaceholder runat server tr table td tr tr id Tr2 runat server td id Td4 runat server td tr table LayoutTemplate asp ListView ul section 3 We have a ListView control on the page called PosterList I set the ItemType property to the Poster class and then the SelectMethod to the GetPosters method I will create this method later on ItemType PostersOnLine DAL Poster SelectMethod GetPosters Then in the code below I have the data binding expression Item available and the control becomes strongly typed So when the user clicks on the link of the poster s category the relevant information will be displayed photo name and price td a href PosterDetails aspx posterID Item PosterID img src Item PosterImgpath width 100 height 75 border 1 a td 4 Now we need to write the simple method to populate the ListView control It is called GetPosters method The code follows public IQueryable Poster GetPosters QueryString id int PosterCatID PosterContext ctx new PosterContext IQueryable Poster query ctx Posters if PosterCatID HasValue PosterCatID 0 query query Where p p PosterCategoryID PosterCatID return query This is a very simple method that returns information about posters related to the PosterCatID passed to it I bind the value from the query string to the PosterCatID parameter at run time This is all possible due to the QueryStringAttribute class that lives inside the System Web ModelBinding and gets the value of the query string variable id 5 I run my application and then click on the Midfilders link Have a look at the picture below to see the results In the Site css file I added some new CSS rules to make everything more presentable posters featured width 840px background color efefef posters featured a link a visited a active a hover color 000033 posters featured a hover background color 85c465 6 I run the application again and this time I do not choose any category I simply navigate to the PosterList aspx page I see all the posters since no query string was passed as a parameter Have a look at the picture below Μake sure you place breakpoints in the code so you can see what is really going on In the next post I will show you how to display poster details Hope it helps Posted Πέμπτη 4 Οκτωβρίου 2012 12 50 πμ από nikolaosk 0 σχόλια Δημοσίευση στην κατηγορία asp net Entity framework data access layer Code First LocalDB Visual Studio 2012 EF 5 0 Building an ASP Net 4 5 Web forms application part 3 Τhis is the third post in a series of posts on how to design and implement an ASP Net 4 5 Web Forms store that sells posters on line Make sure you read the first and second post in the series In this new post I will keep making some minor changes in the Markup CSS and Master page but there is no point in presenting them here They are just minor changes to reflect the content and layout I want my site to have What I need to do now is to add some more pages and start displaying properly data from my database Having said that I will show you how to add more pages to the web application and present data 1 Launch Visual Studio and open your solution where your project lives 2 Add a new web form item on the project Make sure you include the Master Page Name it PosterList aspx Have a look at the picture below 3 In Site Master add the following link to the master page so the user can navigate to it You should only add the line in bold nav ul id menu li a runat server href Home a li li a runat server href About aspx About a li li a runat server href Contact aspx Contact a li li a href http weblogs asp net PosterList aspx Posters a li ul nav 4 Now we need to display categories from the database We will use a ListView web server control Inside the div id body add the following code section id postercat asp ListView ID categoryList ItemType PostersOnLine DAL PosterCategory runat server SelectMethod GetPosterCategories ItemTemplate a href http weblogs asp net PosterList aspx id Item PosterCategoryID Item PosterCategoryName a b ItemTemplate ItemSeparatorTemplate ItemSeparatorTemplate asp ListView section Let me explain what the code does We have the ListView control that displays each poster category s name It also includes a link to the PosterList aspx page with a query string value containing the ID of the category We set the ItemType property in the ListView to the PosterCategory entity We set the SelectMethod property to a method GetPosterCategories Now we can use the data binding expression Item that is available within the ItemTemplate 5 Now we must write the GetPosterCategories method In the Site Master cs file add the following code This is just a simple function that returns the poster categories public IQueryable PosterCategory GetPosterCategories PosterContext ctx new PosterContext IQueryable PosterCategory query ctx PosterCategories return query 6 I just changed a few things in the Site css file to style the new section HTML element that includes the ListView control postercat text align center background color 85C465 7 Build and run your application Everything should compile now Have a look at the picture below The links poster categories appear Τhe ListView control when is called during the page lifecycle calls the GetPosterCategories method The method is executed and returns the poster categories that are bound to the control When I click on any of the poster category links the PosterList aspx page will show up with the appropriate Id that is the PosterCategoryID Have a look at the picture below We will add more data enabled controls in the next post in the PosterList aspx page Some people are complaining the posts are too long so I will keep them short Hope it helps Posted Τετάρτη 3 Οκτωβρίου 2012 1 43 πμ από nikolaosk 0 σχόλια Δημοσίευση στην κατηγορία asp net Entity framework data access layer Code First LocalDB Visual Studio 2012 EF 5 0 Building an ASP Net 4 5 Web forms application part 2 Τhis is the second post in a series of posts on how to design and implement an ASP Net 4 5 Web Forms store that sells posters on line Make sure you read the first post in the series You can find it here In all these posts I am going to publish I will change the layout That means I will make changes to the master css aspx files and images In the final post I will add the whole solution so you can download everything Have a look at the picture below to see the new slightly changed layout Now that we have made the necessary changes to the aspx pages the master page the css files and adding some more images to our site we are ready to move forward and implement the data access layer I will use Entity Framework 5 0 in order to create the data access layer Obviously I cannot go into much detail on what EF is and what it does I will give a short introduction though The Net framework provides support for Object Relational Mapping through EF So EF is a an ORM tool and it is now the main data access technology that microsoft works on I use it quite extensively in my projects Through EF we have many things out of the box provided for us We have the automatic generation of SQL code It maps relational data to strongly types objects All the changes made to the objects in the memory are persisted in a transactional way back to the data store You can find in this post an example on how to use the Entity Framework to retrieve data from an SQL Server Database using the Database Schema First approach In this approach we make all the changes at the database level and then we update the model with those changes In this post you can see an example on how to use the Model First approach when working with ASP Net and the Entity Framework For this project I will use the Code First approach to build the data access layer The Code First approach is the more code centric than the other two Database First Model First Basically we write POCO classes and then we persist to a database using something called DBContext Code First relies on DbContext We create 2 3 classes e g Person Product with properties and then these classes interact with the DbContext class and we can create a new database based upon our POCOS classes and have tables generated from those classes We do not have an edmx file in this approach By using this approach we can write much easier unit tests DbContext is a new context class and is smaller lightweight wrapper for the main context class which is ObjectContext Schema First and Model First Let s implement our POCO classes 1 Launch Visual Studio and open your solution where your project lives 2 Create a new folder Name it DAL or any other name you think it is appropriate We will place in there our entity classes 3 Obviously you must include EF in your solution The good news is that EF is included in any ASP Net Web Forms Application If you are not sure whether you have the latest version or not of the EF then just use NuGet In my case the EF version is 5 0 Have a look at the picture below 4 We also need to add a reference to the System Data Entity namespace Select References from the Solution Explorer and then choose Add Reference You have to browse through the assemblies in the Net Framework until you locate the System Data Entity and the click OK Have a look at the picture below 5 Select the DAL folder then right click and then select Add New Item We will add a class file Poster cs Have a look at the picture below 6 Now we need to write the code for the Poster cs Entity class Please bear in mind that every instance of the Poster class an object will represent a row in the database table and every property in the class declaration will represent a table column The code follows public class Poster ScaffoldColumn false public int PosterID get set StringLength 50 Display Name Poster Name public string PosterName get set Required StringLength 500 Display Name Poster Description DataType DataType MultilineText public string PosterDescription get set public string PosterImgpath get set Display Name Price public double PosterPrice get set 7 Select the DAL folder then right click and then select Add New Item We will add a class file PosterCategory cs The code follows public class PosterCategory ScaffoldColumn false public int PosterCategoryID get set Required StringLength 50 Display Name Category Name public string PosterCategoryName get set Required StringLength 200 Display Name Category Description public string CategoryDescription get set public List Poster Posters get set 8 Select the DAL folder then right click and then select Add New Item We will add another entity class called PosterContext cs This class will inherit from DbContext Now that we have the entity classes created we must let the model know I will have to use the DbSet T property This class manages the domain classes and provides data access to the database Think of it as an orchestrator class The code for this class follows public class PosterContext DbContext public DbSet PosterCategory PosterCategories get set public DbSet Poster Posters get set Do not forget to add using System Data Entity in the beginning of the class file I would like to talk at this point a little bit about Code First Data Annotations With Data Annotations we can configure our domain entity classes so that they can take best advantage of the EF We will decorate our entity classes with declarative attributes Let me give you an insight on how EF Code First works EF Code First at run time looks at the entity domain classes and infers from them the in memory data that it needs to interpret the queries and interact with the database For example it assumes that any property named ID represents the key property of the class Please have a look at this post of mine to find out more about Data Annotations 9 Let s create a new class and add it in the DAL folder I will call it PosterInsert cs In this class I will have the code to initialise the database and insert values The code for this class follows public class PosterInsert DropCreateDatabaseIfModelChanges PosterContext protected override void Seed PosterContext context var pcategory new List PosterCategory new PosterCategory PosterCategoryName Midfielders CategoryDescription Posters of active and past Liverpool Midfielders Posters new List Poster new Poster PosterName King Kenny PosterDescription King Kenny lifting the European Cup PosterImgpath Images posters kenny dalglish jpg PosterPrice 18 95 new Poster PosterName John Barnes PosterDescription El mago a true genius in the midfield PosterImgpath Images posters john barnes jpg PosterPrice 16 95 new Poster PosterName Steven Gerrard PosterDescription The Captain PosterImgpath Images posters steven gerrard jpg PosterPrice 28 95 new PosterCategory PosterCategoryName Defenders CategoryDescription Posters of active and past Liverpool Defenders Posters new List Poster new Poster PosterName Jamie Carragher PosterDescription Th greatest defender in the last ten years PosterImgpath Images posters jamie carragher jpg PosterPrice 21 95 new Poster PosterName Alan Hansen PosterDescription The legendary defender Alan Hansen PosterImgpath Images posters alan hansen jpg PosterPrice 13 95 new Poster PosterName Martin Skrtel PosterDescription The most promising defender playing right now PosterImgpath Images posters martin skrtel jpg PosterPrice 19 95 new PosterCategory PosterCategoryName Strikers CategoryDescription Posters of active and past Liverpool Strikers Posters new List Poster new Poster PosterName Ian Rush PosterDescription The greatest striker to wear a Liverpool shirt PosterImgpath Images posters ian rush jpg PosterPrice 18 45 new Poster PosterName Robbie Fowler PosterDescription Robbie a goal scoring machine PosterImgpath Images posters robbie fowler jpg PosterPrice 18 45 new Poster PosterName Michael Owen PosterDescription The youngest deadliest striker Anfield has even known PosterImgpath Images posters michael owen jpg PosterPrice 16 95 pcategory ForEach post context PosterCategories Add post base Seed context In this class I inherit from the DropCreateDatabaseIfModelChanges PosterContext class and I will override the default behaviour of that class with my class I will ovverride the Seed method with some data Then I create 3 instances of the PosterCategory entity and 9 entities of the Poster entity Then through a simple lambda expression I add the data to the database using this last line of code base Seed context 10 Now we need to make one more change in the Global asax cs In the Application Start event handler routine runs when the application starts we will add this code Database SetInitializer new PosterInsert 11 I have also created a Posters folder inside the Images folder and placed in it the 9 images 12 Build and run your application Everything should compile now Have a look at the picture below to see the structure of the web application so far 13 Now we will create a test page to see if the database is created and populated with values Add a web form page to the application Name it PostersTest Add a gridview web server control on the page Make the page as the Start Page In the Page Load event handling routine type PosterContext ctx new PosterContext var query from postcat in ctx PosterCategories select postcat PosterCategoryName GridView1 DataSource query ToList GridView1 DataBind Build and run your application Have a look below to see the result I have got It seems to work The database is created and populated through the magic of EF Code First Have a look at the web config for the connection string In the Solution Explorer look into the App Data folder If you open the Server Explorer and open the connection to the database in my case PostersOnLine DAL PosterContext mdf I am using LocalDB which is anew version of SQL Express

    Original URL path: http://www.dotnetzone.gr/cs/blogs/dotnetrules/archive/tags/LocalDB/default.aspx (2015-07-15)
    Open archived version from archive

  • Dot Net Rules
    15 Ιανουάριος 2011 14 Δεκέμβριος 2010 9 Νοέμβριος 2010 2 Οκτώβριος 2010 11 Σεπτέμβριος 2010 1 Αύγουστος 2010 3 Απρίλιος 2010 2 Μάρτιος 2010 5 Ιανουάριος 2010 1 Οκτώβριος 2009 2 Σεπτέμβριος 2009 4 Ιούνιος 2009 5 Απρίλιος 2009 1 Μάρτιος 2009 3 Φεβρουάριος 2009 2 Δεκέμβριος 2008 3 Νοέμβριος 2008 10 Σεπτέμβριος 2008 1 Αύγουστος 2008 1 Ιούλιος 2008 9 Ιούνιος 2008 10 Παρουσίαση με Ετικέτες Όλες οι Ετικέτε Localisation RSS asp net ASP NET MVC 4 0 C Visual Studio 2010 Localizing an ASP Net MVC 4 0 application In this post I will demonstrate with a hands on demo how to localise your ASP Net MVC applications The most important thing to point out is that in this world we live in we should expect our site to be visited by various people from different cultures and languages So we must be prepared to have our site internationalised Thankfully ASP Net MVC simplifies the whole internationalisation localisation process I would like to talk about the Thread CurrentCulture property that impacts formatting That means that this property instructs the runtime how it should display strings e g the currency in or or how the date should be displayed The other imporant property is Thread CurrentUICulture which is used by the Resource Manager to look up culture specific resources at run time I have installed VS 2012 Ultimate edition in my Windows 8 machine Υou can use Visual Studio Express 2012 for Web You can install Visual Studio Express 2012 for Web if you download Web Platform Installer You can download this tool from this link 1 I am launching VS 2012 and I will Visual C as the programming language I will also select ASP NET MVC 4 Web Application from the available templates Choose C as the development language and Internet Application I will name my application MvcLocalization All the necessary files are created 2 In the Ιndex chstml view in the Home folder add the following code var mysalary 2450 0m var birthday new DateTime 1980 2 17 div mysalary ToString c div br div birthday ToShortDateString div I just declare two variables and output them back to the screen I format the mysalary value as currency 3 Now we need to change our settings in the web config file In the system web section add globalization culture auto uiCulture auto 4 Build and run your application and you should will see something like the picture below My default culture in this machine is US English So everything is formatted accordingly I go to Internet Explorer I view my app in IE Tools Languages Set Language Preferences and add another language Greek Now I run again my application Now I see the new culture format is applied in both my strings Have a look at the picture below The way ASP Net runtime managed to display everything in the new culture because it identified the Accept Language HTTP Header and the globalization entry in the web

    Original URL path: http://www.dotnetzone.gr/cs/blogs/dotnetrules/archive/tags/Localisation/default.aspx (2015-07-15)
    Open archived version from archive

  • Dot Net Rules
    this post I will do a batch update on a table with traditional EF techniques and then use another library called EF Utilities The performance can be significantly improved with EF Utilities batch CUD create update delete operations EF Utilities EntityFramework Utilities is created by Mikal Eliasson http mikee se MikaelEliasson 1 I will create an empty ASP Net Application Web Forms Application and I give it the name EFUtilitiesUpdate I am using Visual Studio 2013 Ultimate edition 2 I add a new web forms page in the application Leave the default name 3 I will use the AdventureWorks2014 database You can download it here for this application and more specifically the Person Person table I have installed SQL Server 2014 Enterprise edition in my machine SQL Express edition will work fine 4 I will add an ADO Net Entity data model using Database First Follow the wizzard steps create the connection string and then import into the conceptual model the Person Person table which will become an entity in the domain model Have a look at the picture below to see what you must have in Visual Studio 5 I will write a sql statement to acquire rows from the Person Person table Connect to your SQL Server instance Type the following query SELECT EmailPromotion FROM AdventureWorks2014 Person Person WHERE EmailPromotion 0 This query after execution will return 11158 rows We wil create a Batch update operation through our ASP Net web forms application We will also measure the performance of this batch operation We will create a batch operation from our application that will affect all the rows 11158 If we did the batch update from T SQL we would use the following statement UPDATE AdventureWorks2014 Person Person SET EmailPromotion 10 WHERE EmailPromotion 0 6 In our webform in the Page Load event we write the following code We add 10 to every row in the Persons entity to the EmailPromotion column protected void Page Load object sender EventArgs e using AdventureWorks2014Entities ctx new AdventureWorks2014Entities IQueryable Person persons ctx People Where x x EmailPromotion 0 foreach Person person in persons person EmailPromotion person EmailPromotion 10 ctx SaveChanges Make sure you build your application but do not run it just yet 7 I will use the Entity Framework Profiler to gain valuable insight in the batch operation and record metrics regarding the performance You can download it here http www hibernatingrhinos com products efprof You can acquire a trial license very easily Make sure you download and install this fantastic EF profiler Inside the folder where you downloaded the Entity Framework Profiler locate the HibernatingRhinos Profiler Appender DLL We will add a reference to this DLL to our web application Make sure you do that In the Global asax file we need to add the following code to the Application Start event handling routine HibernatingRhinos Profiler Appender EntityFramework EntityFrameworkProfiler Initialize Launch the EF Profiler and then build and run the application The application will update the 11158 rows The

    Original URL path: http://www.dotnetzone.gr/cs/blogs/dotnetrules/archive/tags/performance/default.aspx (2015-07-15)
    Open archived version from archive



  •