<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>TagIt Tags From Database &#8211; Sibeesh Passion</title>
	<atom:link href="https://sibeeshpassion.com/tag/tagit-tags-from-database/feed/" rel="self" type="application/rss+xml" />
	<link>https://sibeeshpassion.com</link>
	<description>My passion towards life</description>
	<lastBuildDate>Wed, 02 Jun 2021 15:23:24 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>/wp-content/uploads/2017/04/Sibeesh_Passion_Logo_Small.png</url>
	<title>TagIt Tags From Database &#8211; Sibeesh Passion</title>
	<link>https://sibeeshpassion.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>TagIt Control With Data From Database Using Angular JS In MVC Web API</title>
		<link>https://sibeeshpassion.com/tagit-control-with-data-from-database-using-angular-js-in-mvc-web-api/</link>
					<comments>https://sibeeshpassion.com/tagit-control-with-data-from-database-using-angular-js-in-mvc-web-api/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Thu, 25 Feb 2016 00:00:46 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Angular]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Web API]]></category>
		<category><![CDATA[Angular JS]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[TagIt]]></category>
		<category><![CDATA[TagIt Tags From Database]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=11245</guid>

					<description><![CDATA[In this article we will learn how to load the tags from database in MVC Web API using Angular JS. Here we are going to use a pretty control called tagIt which does the tag part easier with a lot of configuration options. This article use a normal MVC application which includes the Web API control in it, in addition to it, we uses Angular JS for our client side operations. You can always get the tips/tricks/blogs about these mentioned technologies from the links given below. AngularJS Tips, Tricks, Blogs MVC Tips, Tricks, Blogs Web API Tips, Tricks, Blogs As [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In this article we will learn how to load the tags from database in MVC Web API using Angular JS. Here we are going to use a pretty control called tagIt which does the tag part easier with a lot of configuration options. This article use a normal MVC application which includes the Web API control in it, in addition to it, we uses Angular JS for our client side operations. You can always get the tips/tricks/blogs about these mentioned technologies from the links given below. </p>
<li><a href="http://sibeeshpassion.com/category/angularjs/" target="_blank" rel="noopener">AngularJS Tips, Tricks, Blogs</a></li>
<li><a href="http://sibeeshpassion.com/category/mvc/" target="_blank" rel="noopener">MVC Tips, Tricks, Blogs</a></li>
<li><a href="http://sibeeshpassion.com/category/web-api/" target="_blank" rel="noopener">Web API Tips, Tricks, Blogs</a></li>
<p>As the article title implies, we are actually going to load the tags from a table called tblTags from <a href="http://sibeeshpassion.com/category/SQL/" target="_blank" rel="noopener">SQL </a>Server database.  So now we will go and create our application. I hope you will like this. </p>
<p><strong>Download the source code</strong></p>
<p>You can always download the source code here: <a href="https://code.msdn.microsoft.com/TagIt-Control-With-Data-aa3371f7" target="_blank" rel="noopener">Load Tags From Database Using Angular JS In MVC Web API</a></p>
<p><strong>Background</strong></p>
<p>Few days back I was trying to use the tagIt widget in one of my application. I could do that with some pre defined tags as a variable. Then I thought why don&#8217;t we try some thing like loading these tags from database. Hence my application uses MVC architecture, I selected Web API for retrieving the data from database. I hope someone can find this useful.</p>
<p><strong>Create a MVC application</strong></p>
<p>Click File-> New-> Project then select MVC application.  Before going to start the coding part, make sure that all the required extensions/references are installed. Below are the required things to start with. </p>
<li>Angular JS</li>
<li>TagIt Plugin</li>
<li>jQuery</li>
<p>You can all the items mentioned above from NuGet. Right click on your project name and select Manage NuGet packages.</p>
<div id="attachment_11235" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/02/Manage-NuGet-Package-Window-e1455700665396.png"><img fetchpriority="high" decoding="async" aria-describedby="caption-attachment-11235" src="http://sibeeshpassion.com/wp-content/uploads/2016/02/Manage-NuGet-Package-Window-e1455700665396.png" alt="Manage NuGet Package Window" width="650" height="432" class="size-full wp-image-11235" srcset="/wp-content/uploads/2016/02/Manage-NuGet-Package-Window-e1455700665396.png 650w, /wp-content/uploads/2016/02/Manage-NuGet-Package-Window-e1455700665396-300x199.png 300w, /wp-content/uploads/2016/02/Manage-NuGet-Package-Window-e1455700665396-400x266.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-11235" class="wp-caption-text">Manage NuGet Package Window</p></div>
<p>Once you have installed those items, please make sure that all the items(jQuery, Angular JS files, Tag It JS files like tag-it.js) are loaded in your scripts folder. </p>
<p><strong>Using the code</strong></p>
<p>Before going to load the tags from a database we will try to load our tagit control with some predefined array values. No worries, later we will change this array values to the values we get from database. </p>
<p><em>Include the references in your _Layout.cshtml</em></p>
<p>As we have already installed all the packages we need, now we need to add the references, right?</p>
<p>[html]<br />
@RenderBody()</p>
<p>    @Scripts.Render(&quot;~/bundles/jquery&quot;)<br />
    &lt;script src=&quot;~/Scripts/jquery-2.2.0.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script src=&quot;~/Content/jquery-ui.min.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script src=&quot;~/Scripts/angular.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script src=&quot;~/Scripts/angular-route.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script src=&quot;~/Scripts/tag-it.min.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script src=&quot;~/Scripts/MyScripts/TagScripts.js&quot;&gt;&lt;/script&gt;<br />
    @RenderSection(&quot;scripts&quot;, required: false)<br />
[/html]</p>
<p>Here <em>TagScripts.js</em> is the JavaScript file where we are going to write our own scripts.  </p>
<p><em>Set the changes in View</em></p>
<p>So we have added the references, now we will make the changes in our view. As we uses Angular JS, we will set our ng-app and ng-controller as follows. </p>
<p>[html]<br />
&lt;div ng-app=&quot;tagApp&quot;&gt;<br />
    &lt;div ng-controller=&quot;tagController&quot;&gt;<br />
        &lt;ul id=&quot;tags&quot;&gt;&lt;/ul&gt;<br />
        &lt;div id=&quot;error&quot;&gt;Nothing found!&lt;/div&gt;<br />
    &lt;/div&gt;<br />
&lt;/div&gt;<br />
[/html]</p>
<p>You can give a style as follows if you want.</p>
<p>[css]<br />
&lt;style&gt;<br />
    #tags {<br />
        width: 25%;<br />
    }</p>
<p>    #error {<br />
        display:none;<br />
        font-weight: bold;<br />
        color: #1c94c4;<br />
        font-family: Trebuchet MS,Tahoma,Verdana,Arial,sans-serif;<br />
        font-size: 1.1em;<br />
    }<br />
&lt;/style&gt;<br />
[/css]</p>
<p>Oops!, I forgot to mention, please do not forget to include the CSS style sheets. </p>
<p>[html]<br />
&lt;link href=&quot;~/Content/jquery-ui.css&quot; rel=&quot;stylesheet&quot; /&gt;<br />
&lt;link href=&quot;~/Content/jquery.tagit.css&quot; rel=&quot;stylesheet&quot; /&gt;<br />
[/html]</p>
<p>Now we can write the scripts in our TagScripts.js file. </p>
<p><em>Create Angular App</em></p>
<p>You can create an Angular module as follows. </p>
<p>[js]<br />
var app;<br />
    //Angular App<br />
    app = angular.module(&#8216;tagApp&#8217;, []);<br />
[/js]</p>
<blockquote><p>Here the module name must be same as we have given in ng-app in our view. </p></blockquote>
<p><em>Create Angular Controller</em></p>
<p>You can create an Angular Controller as follows. </p>
<p>[js]<br />
app.controller(&#8216;tagController&#8217;, function ($scope) {<br />
        $(&quot;#tags&quot;).tagit({<br />
            availableTags: availableTags,<br />
            autocomplete: { delay: 0, minLength: 1 },<br />
            beforeTagAdded: function (event, ui) {<br />
                if ($.inArray(ui.tagLabel, availableTags) &lt; 0) {<br />
                    $(&#8216;#error&#8217;).show();<br />
                    return false;<br />
                } else {<br />
                    $(&#8216;#error&#8217;).hide();<br />
                }<br />
            }<br />
        });<br />
    });<br />
[/js]</p>
<p>As you can see we have called tagit() function to initialize the tagit control. Below are the explanations to the options we have given.</p>
<li>availableTags</li>
<p>availableTags are the source we need to apply to the control so that the given items can be shown on user actions. </p>
<li>autocomplelte</i>
<p>autocomplete is a property which enables the auto complete option, when it is true user will get the items listed accordingly for each key press</p>
<li>beforeTagAdded</li>
<p>beforeTagAdded is a callback function which gets fired before we add the new tags to the control. This function can be used to do all the needed tasks before adding the given item to the control. For example, if we need to load only the values from the database and if we need to restrict creating the new tags by the user, means user will be allowed to use only the available tags which is in the available tag array. The preceding code block does what has been explained above.</p>
<p>[js]<br />
if ($.inArray(ui.tagLabel, availableTags) &lt; 0) {<br />
                    $(&#8216;#error&#8217;).show();<br />
                    return false;<br />
                } else {<br />
                    $(&#8216;#error&#8217;).hide();<br />
                }<br />
[/js]</p>
<p>If user tries to add a new tag, we will show the alert div which we already set in our view.</p>
<p>Now it is time to see the control in our view, let us see whether it works fine, if not, we may need to go back and checks again.  </p>
<div id="attachment_11260" style="width: 562px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/02/Tag_It_Control_Defined_Array.png"><img decoding="async" aria-describedby="caption-attachment-11260" src="http://sibeeshpassion.com/wp-content/uploads/2016/02/Tag_It_Control_Defined_Array.png" alt="Tag_It_Control_Defined_Array" width="552" height="169" class="size-full wp-image-11260" srcset="/wp-content/uploads/2016/02/Tag_It_Control_Defined_Array.png 552w, /wp-content/uploads/2016/02/Tag_It_Control_Defined_Array-300x92.png 300w, /wp-content/uploads/2016/02/Tag_It_Control_Defined_Array-400x122.png 400w" sizes="(max-width: 552px) 100vw, 552px" /></a><p id="caption-attachment-11260" class="wp-caption-text">Tag_It_Control_Defined_Array</p></div>
<div id="attachment_11261" style="width: 557px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/02/Tag_It_Control_Defined_Array_If_Nothing_Found.png"><img decoding="async" aria-describedby="caption-attachment-11261" src="http://sibeeshpassion.com/wp-content/uploads/2016/02/Tag_It_Control_Defined_Array_If_Nothing_Found.png" alt="Tag_It_Control_Defined_Array_If_Nothing_Found" width="547" height="135" class="size-full wp-image-11261" srcset="/wp-content/uploads/2016/02/Tag_It_Control_Defined_Array_If_Nothing_Found.png 547w, /wp-content/uploads/2016/02/Tag_It_Control_Defined_Array_If_Nothing_Found-300x74.png 300w, /wp-content/uploads/2016/02/Tag_It_Control_Defined_Array_If_Nothing_Found-400x99.png 400w" sizes="(max-width: 547px) 100vw, 547px" /></a><p id="caption-attachment-11261" class="wp-caption-text">Tag_It_Control_Defined_Array_If_Nothing_Found</p></div>
<p>It seems everything is fine, thank god we don&#8217;t need any debugging 🙂</p>
<p>Now we will create a Web API controller. Oh yeah, we are going to start our real coding. Right click on your controller folder and click new.</p>
<div id="attachment_11238" style="width: 614px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/02/Web_API_controller.png"><img decoding="async" aria-describedby="caption-attachment-11238" src="http://sibeeshpassion.com/wp-content/uploads/2016/02/Web_API_controller.png" alt="Web_API_controller" width="604" height="396" class="size-full wp-image-11238" srcset="/wp-content/uploads/2016/02/Web_API_controller.png 604w, /wp-content/uploads/2016/02/Web_API_controller-300x197.png 300w, /wp-content/uploads/2016/02/Web_API_controller-400x262.png 400w" sizes="(max-width: 604px) 100vw, 604px" /></a><p id="caption-attachment-11238" class="wp-caption-text">Web_API_controller</p></div>
<p>So our Web API controller is ready, then it is time to go to do some Angular JS scripts, don&#8217;t worry we will come back here. </p>
<p>We need to make changes to our Angular JS controller <em>tagController </em> as follows. </p>
<p>[js]<br />
    //Angular Controller<br />
    app.controller(&#8216;tagController&#8217;, function ($scope, tagService) {<br />
        //Angular service call<br />
        var tgs = tagService.getTags();<br />
        if (tgs != undefined) {<br />
            tgs.then(function (d) {<br />
                availableTags = [];<br />
                for (var i = 0; i &lt; d.data.length; i++) {<br />
                    availableTags.push(d.data[i].tagName);<br />
                }</p>
<p>                $(&quot;#tags&quot;).tagit({<br />
                    availableTags: availableTags,<br />
                    autocomplete: { delay: 0, minLength: 1 },<br />
                    beforeTagAdded: function (event, ui) {<br />
                        if ($.inArray(ui.tagLabel, availableTags) &lt; 0) {<br />
                            $(&#8216;#error&#8217;).show();<br />
                            return false;<br />
                        } else {<br />
                            $(&#8216;#error&#8217;).hide();<br />
                        }<br />
                    }<br />
                });<br />
                console.log(JSON.stringify(availableTags));<br />
            }, function (error) {<br />
                console.log(&#8216;Oops! Something went wrong while fetching the data.&#8217;);<br />
            });<br />
        }<br />
    });<br />
[/js]</p>
<p>As you have noticed, we are calling an Angular JS service here. Once we get the data from the service, we are assigning it to the array which we have initialized with the predefined values, so that the data from the database will be available in the tagit control. So can we create our Angular JS service?</p>
<p>[js]<br />
    //Angular Service<br />
    app.service(&#8216;tagService&#8217;, function ($http) {<br />
        //call the web api controller<br />
        this.getTags = function () {<br />
            return $http({<br />
                method: &#8216;get&#8217;,<br />
                url: &#8216;api/tag&#8217;<br />
            });<br />
        }<br />
    });<br />
[/js]</p>
<p>This will fire our Web API controller and action GET api/tag. And the Web API controller will give you the results which we will format again and give to the available tag array. Sounds cool? Wait, we can do all these stuffs without Angular JS, means we can simply call a jQuery Ajax Get. Do you want to see how? Here it is. </p>
<p>[js]<br />
/* Using jQuery */</p>
<p>$(function () {<br />
    var availableTags = [<br />
      &quot;ActionScript&quot;,<br />
      &quot;AppleScript&quot;,<br />
      &quot;Asp&quot;,<br />
      &quot;BASIC&quot;,<br />
      &quot;C&quot;,<br />
      &quot;C++&quot;,<br />
      &quot;Clojure&quot;,<br />
      &quot;COBOL&quot;,<br />
      &quot;ColdFusion&quot;,<br />
      &quot;Erlang&quot;,<br />
      &quot;Fortran&quot;,<br />
      &quot;Groovy&quot;,<br />
      &quot;Haskell&quot;,<br />
      &quot;Java&quot;,<br />
      &quot;JavaScript&quot;,<br />
      &quot;Lisp&quot;,<br />
      &quot;Perl&quot;,<br />
      &quot;PHP&quot;,<br />
      &quot;Python&quot;,<br />
      &quot;Ruby&quot;,<br />
      &quot;Scala&quot;,<br />
      &quot;Scheme&quot;<br />
    ];<br />
    //Load the available tags from database start<br />
    $.ajax({<br />
        type: &#8216;GET&#8217;,<br />
        dataType: &#8216;json&#8217;,<br />
        contentType: &#8216;application/json;charset=utf-8&#8217;,<br />
        url: &#8216;http://localhost:56076/api/Tag&#8217;,<br />
        success: function (data) {<br />
            try {<br />
                if (data.length &gt; 0) {<br />
                    availableTags = data;<br />
                }<br />
            } catch (e) {<br />
                console.log(&#8216;Error while formatting the data : &#8216; + e.message)<br />
            }<br />
        },<br />
        error: function (xhrequest, error, thrownError) {<br />
            console.log(&#8216;Error while ajax call: &#8216; + error)<br />
        }<br />
    });<br />
    //Load the available tags from database end</p>
<p>    $(&quot;#tags&quot;).tagit({<br />
        availableTags: availableTags,<br />
        autocomplete: { delay: 0, minLength: 1 },<br />
        beforeTagAdded: function (event, ui) {<br />
            if ($.inArray(ui.tagLabel, availableTags) &lt; 0) {<br />
                $(&#8216;#error&#8217;).show();<br />
                return false;<br />
            } else {<br />
                $(&#8216;#error&#8217;).hide();<br />
            }<br />
        }<br />
    });<br />
});<br />
[/js]</p>
<p>Now only thing pending is to get the data from our API controller, we will see that part now. For that first you must create a database and a table in it right?</p>
<p><strong>Create a database</strong></p>
<p>The following query can be used to create a database in your SQL Server.</p>
<p>[sql]<br />
USE [master]<br />
GO</p>
<p>/****** Object:  Database [TrialsDB]    Script Date: 17-Feb-16 10:21:17 PM ******/<br />
CREATE DATABASE [TrialsDB]<br />
 CONTAINMENT = NONE<br />
 ON  PRIMARY<br />
( NAME = N&#8217;TrialsDB&#8217;, FILENAME = N&#8217;C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\TrialsDB.mdf&#8217; , SIZE = 3072KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )<br />
 LOG ON<br />
( NAME = N&#8217;TrialsDB_log&#8217;, FILENAME = N&#8217;C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\TrialsDB_log.ldf&#8217; , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET COMPATIBILITY_LEVEL = 110<br />
GO</p>
<p>IF (1 = FULLTEXTSERVICEPROPERTY(&#8216;IsFullTextInstalled&#8217;))<br />
begin<br />
EXEC [TrialsDB].[dbo].[sp_fulltext_database] @action = &#8216;enable&#8217;<br />
end<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET ANSI_NULL_DEFAULT OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET ANSI_NULLS OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET ANSI_PADDING OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET ANSI_WARNINGS OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET ARITHABORT OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET AUTO_CLOSE OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET AUTO_CREATE_STATISTICS ON<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET AUTO_SHRINK OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET AUTO_UPDATE_STATISTICS ON<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET CURSOR_CLOSE_ON_COMMIT OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET CURSOR_DEFAULT  GLOBAL<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET CONCAT_NULL_YIELDS_NULL OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET NUMERIC_ROUNDABORT OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET QUOTED_IDENTIFIER OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET RECURSIVE_TRIGGERS OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET  DISABLE_BROKER<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET AUTO_UPDATE_STATISTICS_ASYNC OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET DATE_CORRELATION_OPTIMIZATION OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET TRUSTWORTHY OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET ALLOW_SNAPSHOT_ISOLATION OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET PARAMETERIZATION SIMPLE<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET READ_COMMITTED_SNAPSHOT OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET HONOR_BROKER_PRIORITY OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET RECOVERY FULL<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET  MULTI_USER<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET PAGE_VERIFY CHECKSUM<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET DB_CHAINING OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF )<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET TARGET_RECOVERY_TIME = 0 SECONDS<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET  READ_WRITE<br />
GO<br />
[/sql]</p>
<p>Now we will create a table 🙂</p>
<p><strong>Create table in database</strong></p>
<p>Below is the query to create table in database.</p>
<p>[sql]<br />
USE [TrialsDB]<br />
GO</p>
<p>/****** Object:  Table [dbo].[tblTags]    Script Date: 17-Feb-16 10:22:00 PM ******/<br />
SET ANSI_NULLS ON<br />
GO</p>
<p>SET QUOTED_IDENTIFIER ON<br />
GO</p>
<p>CREATE TABLE [dbo].[tblTags](<br />
	[tagId] [int] IDENTITY(1,1) NOT NULL,<br />
	[tagName] [nvarchar](50) NOT NULL,<br />
	[tagDescription] [nvarchar](max) NULL,<br />
 CONSTRAINT [PK_tblTags] PRIMARY KEY CLUSTERED<br />
(<br />
	[tagId] ASC<br />
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]<br />
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]</p>
<p>GO<br />
[/sql]</p>
<p>Can we insert some data to the table now?</p>
<p><strong>Insert data to table</strong></p>
<p>You can use the below query to insert the data.</p>
<p>[sql]<br />
USE [TrialsDB]<br />
GO</p>
<p>INSERT INTO [dbo].[tblTags]<br />
           ([tagName]<br />
           ,[tagDescription])<br />
     VALUES<br />
           (&lt;tagName, nvarchar(50),&gt;<br />
           ,&lt;tagDescription, nvarchar(max),&gt;)<br />
GO<br />
[/sql]</p>
<p>So let us say, we have inserted the data as follows.</p>
<div id="attachment_11248" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/02/Insertion_In_Table-e1455728194631.png"><img decoding="async" aria-describedby="caption-attachment-11248" src="http://sibeeshpassion.com/wp-content/uploads/2016/02/Insertion_In_Table-e1455728194631.png" alt="Insertion_In_Table" width="650" height="176" class="size-full wp-image-11248" srcset="/wp-content/uploads/2016/02/Insertion_In_Table-e1455728194631.png 650w, /wp-content/uploads/2016/02/Insertion_In_Table-e1455728194631-300x81.png 300w, /wp-content/uploads/2016/02/Insertion_In_Table-e1455728194631-400x108.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-11248" class="wp-caption-text">Insertion_In_Table</p></div>
<p>Next thing we are going to do is creating a ADO.NET Entity Data Model. </p>
<p><strong>Create Entity Data Model</strong></p>
<p>Right click on your model folder and click new, select ADO.NET Entity Data Model. Follow the steps given. Once you have done the processes, you can see the edmx file and other files in your model folder. </p>
<div id="attachment_11249" style="width: 339px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/02/ADO_NET_Model_Entity.png"><img decoding="async" aria-describedby="caption-attachment-11249" src="http://sibeeshpassion.com/wp-content/uploads/2016/02/ADO_NET_Model_Entity.png" alt="ADO_NET_Model_Entity" width="329" height="207" class="size-full wp-image-11249" srcset="/wp-content/uploads/2016/02/ADO_NET_Model_Entity.png 329w, /wp-content/uploads/2016/02/ADO_NET_Model_Entity-300x189.png 300w" sizes="(max-width: 329px) 100vw, 329px" /></a><p id="caption-attachment-11249" class="wp-caption-text">ADO_NET_Model_Entity</p></div>
<p>Then it is time to go back our Web API controller. Please change the code as below.</p>
<p>[csharp]<br />
using System;<br />
using System.Collections.Generic;<br />
using System.Data;<br />
using System.Data.Entity;<br />
using System.Data.Entity.Infrastructure;<br />
using System.Linq;<br />
using System.Net;<br />
using System.Net.Http;<br />
using System.Web;<br />
using System.Web.Http;<br />
using Load_Tags_From_DB_Using_Angular_JS_In_MVC.Models;</p>
<p>namespace Load_Tags_From_DB_Using_Angular_JS_In_MVC.Controllers<br />
{<br />
    public class TagController : ApiController<br />
    {<br />
        private DBEntities db = new DBEntities();</p>
<p>        // GET api/Tag<br />
        public IEnumerable&lt;tblTag&gt; Get()<br />
        {<br />
            return db.tblTags.AsEnumerable();<br />
        }<br />
    }<br />
}<br />
[/csharp]</p>
<p>Once this is done, we can say that we are finished with all steps. That&#8217;s fantastic right? Now we will see the output.</p>
<p><strong>Output</strong></p>
<div id="attachment_11250" style="width: 563px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/02/Load_Tags_From_Database_Output.png"><img decoding="async" aria-describedby="caption-attachment-11250" src="http://sibeeshpassion.com/wp-content/uploads/2016/02/Load_Tags_From_Database_Output.png" alt="Load_Tags_From_Database_Output" width="553" height="146" class="size-full wp-image-11250" srcset="/wp-content/uploads/2016/02/Load_Tags_From_Database_Output.png 553w, /wp-content/uploads/2016/02/Load_Tags_From_Database_Output-300x79.png 300w, /wp-content/uploads/2016/02/Load_Tags_From_Database_Output-400x106.png 400w" sizes="(max-width: 553px) 100vw, 553px" /></a><p id="caption-attachment-11250" class="wp-caption-text">Load_Tags_From_Database_Output</p></div>
<p>Have a happy coding.</p>
<p><strong>Conclusion</strong></p>
<p>Did I miss anything that you may think which is needed? Did you try Web API yet? Have you ever wanted to do this requirement? Could you find this post as useful? I hope you liked this article. Please share me your valuable suggestions and feedback.</p>
<p><strong>Your turn. What do you think?</strong></p>
<p>A blog isn&#8217;t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can.</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/tagit-control-with-data-from-database-using-angular-js-in-mvc-web-api/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
