<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-2134748813367998500</id><updated>2024-11-08T07:11:44.519-08:00</updated><category term="SQL"/><category term=".NET"/><category term="ASP"/><category term="Entity"/><category term="Framework"/><category term="LinQ"/><category term="MVC"/><category term="jQuery"/><category term="DropDownList"/><category term="HTML"/><category term="Select"/><category term="pqGrid"/><title type='text'>Programacion y otras cosas</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://quoacademico.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2134748813367998500/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://quoacademico.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16735065261569552657</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>5</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2134748813367998500.post-3161146468498588192</id><published>2013-10-11T09:31:00.000-07:00</published><updated>2013-10-11T09:52:00.565-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term=".NET"/><category scheme="http://www.blogger.com/atom/ns#" term="ASP"/><category scheme="http://www.blogger.com/atom/ns#" term="DropDownList"/><category scheme="http://www.blogger.com/atom/ns#" term="Entity"/><category scheme="http://www.blogger.com/atom/ns#" term="Framework"/><category scheme="http://www.blogger.com/atom/ns#" term="HTML"/><category scheme="http://www.blogger.com/atom/ns#" term="jQuery"/><category scheme="http://www.blogger.com/atom/ns#" term="LinQ"/><category scheme="http://www.blogger.com/atom/ns#" term="MVC"/><category scheme="http://www.blogger.com/atom/ns#" term="Select"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL"/><title type='text'>Cascadeo de DropDownList con MVC</title><content type='html'>&lt;div align=&quot;justify&quot;&gt;
Saludos amigos, nuevamente hoy les traigo un tema muy sencillo 
en realidad, aunque espero en verdad en que a mas de uno le sea de utilidad, y 
es como cascadear los DropDownList en Razor usando MVC.&lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
Realmente esto es muy fácil de hacer y lo voy a demostrar a 
continuación.&lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
Lo que vamos a hacer es crear un DropDownList con la 
información de Empresas y cascadearemos este con otro DropDownList con 
información de las Sucursales pertenecientes a la empresa que hayamos 
seleccionado.&lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
Los requisitos que para esto es tener la base de datos que 
hemos estado utilizando para los ejemplos, si no lo han seguido conmigo pueden 
descargar el script inicial &lt;a href=&quot;http://adf.ly/XIXFi&quot; target=&quot;_blank&quot;&gt;aquí&lt;/a&gt; 
ya que tienen la base de datos, actualícenla con las tablas de empresa y 
Sucursales con el script que pueden descargar de &lt;a href=&quot;http://adf.ly/XLxp4&quot; target=&quot;_blank&quot;&gt;aquí&lt;/a&gt;.&lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
Ya que lo hemos ejecutado y por lo tanto actualizado nuestra 
base de datos, haremos lo siguiente, entraremos al archivo de modelo que ya 
hemos creado con anterioridad, y si no tienen el archivo de modelo pueden crear 
el modelo a partir de la base de datos, si no saben como hacer esto en la 
entrada anterior a esta explico paso a paso como hacerlo.&lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
Bueno ya que tenemos nuestra base de datos con alguna 
información que para probar deben de generar, vamos a escribir el código del 
Controller.&lt;/div&gt;
&lt;br/&gt;
&lt;div align=&quot;justify&quot;&gt;
Vamos a agregar la siguiente función:&lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
&lt;br/&gt;&lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
&lt;br/&gt;&lt;/div&gt;
&lt;style type=&quot;text/css&quot;&gt;.csharpcode, .csharpcode pre
{
 font-size: small;
 color: black;
 font-family: consolas, &quot;Courier New&quot;, courier, monospace;
 background-color: #ffffff;
 /*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
 background-color: #f4f4f4;
 width: 100%;
 margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;div class=&quot;csharpcode&quot; align=&quot;justify&quot;&gt;&lt;pre class=&quot;alt&quot;&gt;&lt;span class=&quot;lnum&quot;&gt;   1:  &lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; ActionResult TrabajandoConComboBox() &lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;csharpcode&quot; align=&quot;justify&quot;&gt;&lt;pre&gt;&lt;span class=&quot;lnum&quot;&gt;   2:  &lt;/span&gt;            &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; PartialView();&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;csharpcode&quot; align=&quot;justify&quot;&gt;&lt;pre class=&quot;alt&quot;&gt;&lt;span class=&quot;lnum&quot;&gt;   3:  &lt;/span&gt;        }&lt;/pre&gt;&lt;/div&gt;

&lt;p align=&quot;justify&quot;&gt;Note que yo estoy usando una vista parcial, pero funciona también con una vista normal. ya que tenemos esta función vamos a dar clic derecho sobre la función y vamos a generar la vista en la cual agregaremos la funcionalidad de los DropDownList, ya que generamos la vista vamos a regresar a esta misma función para agregar la carga inicial de nuestro primer DropDownList, aquí haremos la extracción de las empresas y la pondremos en la ViewBag de nuestra vista, la función debe de quedar de la siguiente manera:&lt;/p&gt;
&lt;div class=&quot;csharpcode&quot; align=&quot;justify&quot;&gt;&lt;pre class=&quot;alt&quot;&gt;&lt;span class=&quot;lnum&quot;&gt;   1:  &lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; ActionResult TrabajandoConComboBox() &lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;csharpcode&quot; align=&quot;justify&quot;&gt;&lt;pre&gt;&lt;span class=&quot;lnum&quot;&gt;   2:  &lt;/span&gt;{&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;csharpcode&quot; align=&quot;justify&quot;&gt;&lt;pre class=&quot;alt&quot;&gt;&lt;span class=&quot;lnum&quot;&gt;   3:  &lt;/span&gt;   Models.TutorialMVCEntities Context = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; Models.TutorialMVCEntities();&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;csharpcode&quot; align=&quot;justify&quot;&gt;&lt;pre&gt;&lt;span class=&quot;lnum&quot;&gt;   4:  &lt;/span&gt;   var _Empresas = Context.Empresas.Select(x =&amp;gt; &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt;  SelectListItem{  Text = x.Nombre, Value = x.Nombre}).ToList();&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;csharpcode&quot; align=&quot;justify&quot;&gt;&lt;pre class=&quot;alt&quot;&gt;&lt;span class=&quot;lnum&quot;&gt;   5:  &lt;/span&gt;   ViewBag.Empresas = _Empresas;&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;csharpcode&quot; align=&quot;justify&quot;&gt;&lt;pre&gt;&lt;span class=&quot;lnum&quot;&gt;   6:  &lt;/span&gt;   &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; PartialView();&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;csharpcode&quot; align=&quot;justify&quot;&gt;&lt;pre class=&quot;alt&quot;&gt;&lt;span class=&quot;lnum&quot;&gt;   7:  &lt;/span&gt;}&lt;/pre&gt;&lt;/div&gt;
&lt;p align=&quot;justify&quot;&gt;como podemos percatarnos estamos haciendo la extracción de la información de las empresas y con ello creamos una lista del objeto SelectListItem el cual se agregaran como las opciones de nuestro primer DropDownList el cual contendrá las empresas.&lt;/p&gt;
&lt;p align=&quot;justify&quot;&gt;Ahora vamos a agregar esta primera funcionalidad a nuestra vista, antes de iniciar con la vista note en el código anterior que se agrega al ViewBag una variable llamada Empresas la cual es la que contiene las opciones de nuestro DropDownList, bueno, pasamos a nuestra vista y agregaremos la siguiente línea de código:&lt;/p&gt;
&lt;div class=&quot;csharpcode&quot;&gt;&lt;pre class=&quot;alt&quot;&gt;&lt;span class=&quot;lnum&quot;&gt;   1:  &lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class=&quot;lnum&quot;&gt;   2:  &lt;/span&gt;   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;Empresas: &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre class=&quot;alt&quot;&gt;&lt;span class=&quot;lnum&quot;&gt;   3:  &lt;/span&gt;    @Html.DropDownList(&quot;Empresas&quot;,&quot;&quot;)&lt;/pre&gt;&lt;pre&gt;&lt;span class=&quot;lnum&quot;&gt;   4:  &lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;style type=&quot;text/css&quot;&gt;.csharpcode, .csharpcode pre
{
 font-size: small;
 color: black;
 font-family: consolas, &quot;Courier New&quot;, courier, monospace;
 background-color: #ffffff;
 /*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
 background-color: #f4f4f4;
 width: 100%;
 margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;y si quieren pueden ejecutarlo, esto les dará como resultado un DropDownList con la información de la empresas que hayan dado de alta en su base de datos.&lt;/p&gt;
&lt;p&gt;Ya que hemos visto que funciona, vamos a lo mas interesante, vamos a obtener las sucursales que le pertenecen a la empresa que seleccionamos. vamos a regresar a nuestro controlador y agregaremos la siguiente función:&lt;/p&gt;
&lt;div class=&quot;csharpcode&quot;&gt;&lt;pre class=&quot;alt&quot;&gt;&lt;span class=&quot;lnum&quot;&gt;   1:  &lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; JsonResult ObtieneSucursales(&lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; Empresa) &lt;/pre&gt;&lt;pre&gt;&lt;span class=&quot;lnum&quot;&gt;   2:  &lt;/span&gt;{&lt;/pre&gt;&lt;pre class=&quot;alt&quot;&gt;&lt;span class=&quot;lnum&quot;&gt;   3:  &lt;/span&gt;  Models.TutorialMVCEntities Context = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; Models.TutorialMVCEntities();&lt;/pre&gt;&lt;pre&gt;&lt;span class=&quot;lnum&quot;&gt;   4:  &lt;/span&gt;  var _Sucursales = Context.Sucursales&lt;/pre&gt;&lt;pre class=&quot;alt&quot;&gt;&lt;span class=&quot;lnum&quot;&gt;   5:  &lt;/span&gt;                   .Where(x=&amp;gt; x.Empresas.Nombre==Empresa)&lt;/pre&gt;&lt;pre&gt;&lt;span class=&quot;lnum&quot;&gt;   6:  &lt;/span&gt;                   .Select(x =&amp;gt; &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; { Id = x.Id, Nombre = x.Nombre });&lt;/pre&gt;&lt;pre class=&quot;alt&quot;&gt;&lt;span class=&quot;lnum&quot;&gt;   7:  &lt;/span&gt;  &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; Json(_Sucursales, JsonRequestBehavior.AllowGet);&lt;/pre&gt;&lt;pre&gt;&lt;span class=&quot;lnum&quot;&gt;   8:  &lt;/span&gt;}&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;esta función note que devuelve los valores en JSON debido a que la actualización la realizaremos mediante javascript en un Select de HTML. aquí vemos como filtramos las sucursales de acuerdo a la empresa que se recibió como parámetro.&lt;/p&gt;
&lt;p&gt;ahora vamos a regresar a la vista y agregamos el siguiente código debajo de el DropDownList:&lt;/p&gt;
&lt;div class=&quot;csharpcode&quot;&gt;&lt;pre class=&quot;alt&quot;&gt;&lt;span class=&quot;lnum&quot;&gt;   1:  &lt;/span&gt;&amp;lt;p&amp;gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class=&quot;lnum&quot;&gt;   2:  &lt;/span&gt;  &amp;lt;a&amp;gt;Sucursales: &amp;lt;/a&amp;gt;&lt;/pre&gt;&lt;pre class=&quot;alt&quot;&gt;&lt;span class=&quot;lnum&quot;&gt;   3:  &lt;/span&gt;  &amp;lt;select id=&lt;span class=&quot;str&quot;&gt;&quot;Sucursales&quot;&lt;/span&gt; /&amp;gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class=&quot;lnum&quot;&gt;   4:  &lt;/span&gt;&amp;lt;/p&amp;gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;y en la parte superior agregue el siguiente script:&lt;/p&gt;
&lt;div class=&quot;csharpcode&quot;&gt;&lt;pre class=&quot;alt&quot;&gt;&lt;span class=&quot;lnum&quot;&gt;   1:  &lt;/span&gt;&amp;lt;script&amp;gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class=&quot;lnum&quot;&gt;   2:  &lt;/span&gt;    $(document).ready(&lt;span class=&quot;kwrd&quot;&gt;function&lt;/span&gt; () {&lt;/pre&gt;&lt;pre class=&quot;alt&quot;&gt;&lt;span class=&quot;lnum&quot;&gt;   3:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&lt;span class=&quot;lnum&quot;&gt;   4:  &lt;/span&gt;        $(&lt;span class=&quot;str&quot;&gt;&quot;#Empresas&quot;&lt;/span&gt;).change(&lt;span class=&quot;kwrd&quot;&gt;function&lt;/span&gt; () {&lt;/pre&gt;&lt;pre class=&quot;alt&quot;&gt;&lt;span class=&quot;lnum&quot;&gt;   5:  &lt;/span&gt;            $.ajax({&lt;/pre&gt;&lt;pre&gt;&lt;span class=&quot;lnum&quot;&gt;   6:  &lt;/span&gt;                type: &lt;span class=&quot;str&quot;&gt;&#39;POST&#39;&lt;/span&gt;,&lt;/pre&gt;&lt;pre class=&quot;alt&quot;&gt;&lt;span class=&quot;lnum&quot;&gt;   7:  &lt;/span&gt;                url: &lt;span class=&quot;str&quot;&gt;&#39;/Home/ObtieneSucursales?Empresa=&#39;&lt;/span&gt; + $(&lt;span class=&quot;str&quot;&gt;&quot;#Empresas&quot;&lt;/span&gt;).val(),&lt;/pre&gt;&lt;pre&gt;&lt;span class=&quot;lnum&quot;&gt;   8:  &lt;/span&gt;                dataType: &lt;span class=&quot;str&quot;&gt;&#39;json&#39;&lt;/span&gt;,&lt;/pre&gt;&lt;pre class=&quot;alt&quot;&gt;&lt;span class=&quot;lnum&quot;&gt;   9:  &lt;/span&gt;                success: &lt;span class=&quot;kwrd&quot;&gt;function&lt;/span&gt; (data) {&lt;/pre&gt;&lt;pre&gt;&lt;span class=&quot;lnum&quot;&gt;  10:  &lt;/span&gt;                    &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; options = &lt;span class=&quot;str&quot;&gt;&#39;&amp;lt;option value=&quot;&quot;/&amp;gt;&#39;&lt;/span&gt;;&lt;/pre&gt;&lt;pre class=&quot;alt&quot;&gt;&lt;span class=&quot;lnum&quot;&gt;  11:  &lt;/span&gt;                    &lt;span class=&quot;kwrd&quot;&gt;for&lt;/span&gt; (&lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; i = 0; i &amp;lt; data.length; i++) {&lt;/pre&gt;&lt;pre&gt;&lt;span class=&quot;lnum&quot;&gt;  12:  &lt;/span&gt;                        options += &lt;span class=&quot;str&quot;&gt;&#39;&amp;lt;option value=&quot;&#39;&lt;/span&gt; + data[i].Id + &lt;span class=&quot;str&quot;&gt;&#39;&quot;&amp;gt;&#39;&lt;/span&gt; + data[i].Nombre + &lt;span class=&quot;str&quot;&gt;&#39;&amp;lt;/option&amp;gt;&#39;&lt;/span&gt;;&lt;/pre&gt;&lt;pre class=&quot;alt&quot;&gt;&lt;span class=&quot;lnum&quot;&gt;  13:  &lt;/span&gt;                    }&lt;/pre&gt;&lt;pre&gt;&lt;span class=&quot;lnum&quot;&gt;  14:  &lt;/span&gt;                    $(&lt;span class=&quot;str&quot;&gt;&quot;#Sucursales&quot;&lt;/span&gt;).html(options);&lt;/pre&gt;&lt;pre class=&quot;alt&quot;&gt;&lt;span class=&quot;lnum&quot;&gt;  15:  &lt;/span&gt;                },&lt;/pre&gt;&lt;pre&gt;&lt;span class=&quot;lnum&quot;&gt;  16:  &lt;/span&gt;                error: &lt;span class=&quot;kwrd&quot;&gt;function&lt;/span&gt; (xhr, ajaxOptions, error) {&lt;/pre&gt;&lt;pre class=&quot;alt&quot;&gt;&lt;span class=&quot;lnum&quot;&gt;  17:  &lt;/span&gt;                    alert(xhr.status);&lt;/pre&gt;&lt;pre&gt;&lt;span class=&quot;lnum&quot;&gt;  18:  &lt;/span&gt;                    alert(&lt;span class=&quot;str&quot;&gt;&#39;Error: &#39;&lt;/span&gt; + xhr.responseText);&lt;/pre&gt;&lt;pre class=&quot;alt&quot;&gt;&lt;span class=&quot;lnum&quot;&gt;  19:  &lt;/span&gt;                }&lt;/pre&gt;&lt;pre&gt;&lt;span class=&quot;lnum&quot;&gt;  20:  &lt;/span&gt;            });&lt;/pre&gt;&lt;pre class=&quot;alt&quot;&gt;&lt;span class=&quot;lnum&quot;&gt;  21:  &lt;/span&gt;        });&lt;/pre&gt;&lt;pre&gt;&lt;span class=&quot;lnum&quot;&gt;  22:  &lt;/span&gt;    });&lt;/pre&gt;&lt;pre class=&quot;alt&quot;&gt;&lt;span class=&quot;lnum&quot;&gt;  23:  &lt;/span&gt;&amp;lt;/script&amp;gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;y listo aquí ejecuten su proyecto y al momento de que seleccione un registro en el DropDownList de empresas inmediatamente se realizara la carga de opciones en el DropDownList de Sucursales.&lt;/p&gt;
&lt;p&gt;Pues bueno amigos espero que este pequeñisimo tutorial sea de utilidad para ustedes.&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://quoacademico.blogspot.com/feeds/3161146468498588192/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://quoacademico.blogspot.com/2013/10/cascadeo-de-dropdownlist-con-mvc.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2134748813367998500/posts/default/3161146468498588192'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2134748813367998500/posts/default/3161146468498588192'/><link rel='alternate' type='text/html' href='http://quoacademico.blogspot.com/2013/10/cascadeo-de-dropdownlist-con-mvc.html' title='Cascadeo de DropDownList con MVC'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16735065261569552657</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2134748813367998500.post-7333658217494487267</id><published>2013-10-10T13:07:00.001-07:00</published><updated>2013-10-11T09:56:16.670-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term=".NET"/><category scheme="http://www.blogger.com/atom/ns#" term="ASP"/><category scheme="http://www.blogger.com/atom/ns#" term="Entity"/><category scheme="http://www.blogger.com/atom/ns#" term="Framework"/><category scheme="http://www.blogger.com/atom/ns#" term="jQuery"/><category scheme="http://www.blogger.com/atom/ns#" term="LinQ"/><category scheme="http://www.blogger.com/atom/ns#" term="MVC"/><category scheme="http://www.blogger.com/atom/ns#" term="pqGrid"/><title type='text'>Como: Mostrar datos con ASP.NET MVC 4 y Entity Framework</title><content type='html'>Saludos amigos, en esta ocasión les traigo un tema con el que seguramente muchos de ustedes se están rompiendo la cabeza o se la piensan romper, y esto es el cómo mostrar información en un sitio web con la utilización de Entity Framework y ASP.Net MVC. Bueno, para poder lograr esto primeramente voy a hablar un poco de los elementos que vamos a utilizar para la prueba. En el mercado existen muchos controles y plugins de diversos fabricantes para el objetivo de mostrar datos tabulares desde un origen de datos, y para nosotros son sumamente necesarios, por lo que en este pequeño tutorial voy a utilizar un plugin que me pareció muy útil y espero que para ustedes también, el plugin se llama &lt;b&gt;jQuery Grid Plugin&lt;/b&gt; y lo pueden ver en acción con todas sus funcionalidades dentro de su página &lt;a href=&quot;http://adf.ly/XIYUh&quot;&gt;http://paramquery.com/grid&lt;/a&gt;, sin embargo, aquí solo vamos a usar la parte más básica de este que es la de mostrar información.  &lt;br /&gt;
En este tutorial también vamos a usar ASP.Net MVC 4 por lo que se requieren conocimientos mínimos de esta plataforma, en caso de que no sea así, pueden seguir el tutorial, pero, posiblemente les generen algunas dudas las cuales no se resolverán en este tutorial, sin embargo, pueden comentarlas y con gusto las resolveremos poco a poco. También necesitamos tener conocimientos previos de SQL y LinQ. Ya sin mas preámbulo entremos en el tema que nos atañe, como hacer una página web que nos muestre la información de la base de datos en un grid con el patrón MVC y jQuery.  &lt;br /&gt;
Lo primero que vamos a hacer es crear un proyecto de tipo &lt;strong&gt;ASP.NET MVC 4 Web Application&lt;/strong&gt; (para este ejemplo estoy usando la versión 2010 de Visual Studio)  &lt;br /&gt;
&amp;nbsp; &lt;br /&gt;
&lt;a href=&quot;http://lh4.ggpht.com/-bGneDJJACFc/UlcH0B1UXDI/AAAAAAAAAIA/ETgctNWEc34/s1600-h/SNAGHTML7b11424%25255B4%25255D.png&quot;&gt;&lt;img alt=&quot;SNAGHTML7b11424&quot; border=&quot;0&quot; height=&quot;114&quot; src=&quot;http://lh4.ggpht.com/-ONFy4kKN6_g/UlcH0ltO5gI/AAAAAAAAAII/s3mpvZXm7RU/SNAGHTML7b11424_thumb%25255B1%25255D.png?imgmax=800&quot; style=&quot;background-image: none; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot; title=&quot;SNAGHTML7b11424&quot; width=&quot;453&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
 Cuando les solicite la configuración de su proyecto seleccionen el &lt;strong&gt;Basic &lt;/strong&gt;y View engine RAZOR ya que es la configuración con la que realizaremos el tutorial.&lt;br /&gt;
 &lt;div align=&quot;center&quot;&gt;
&lt;a href=&quot;http://lh3.ggpht.com/-It3DpyX3Hes/UlcH1P5DLuI/AAAAAAAAAIQ/5kIe9Baqf4A/s1600-h/image%25255B3%25255D.png&quot;&gt;&lt;img alt=&quot;image&quot; border=&quot;0&quot; height=&quot;257&quot; src=&quot;http://lh4.ggpht.com/-GkmlK3VeuuI/UlcH1vJyjOI/AAAAAAAAAIY/PBGwFAiVH8s/image_thumb%25255B1%25255D.png?imgmax=800&quot; style=&quot;background-image: none; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot; title=&quot;image&quot; width=&quot;444&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
Ya que tengamos creado nuestro proyecto debemos de agregar las librerias de jQuery y jQueryUI las cuales las pueden descargar de &lt;a href=&quot;http://adf.ly/XIYQp&quot; target=&quot;_blank&quot;&gt;aqui&lt;/a&gt; o en todo caso usen la instalación de estas a traves de NuGet, sin embargo, si estan pensando en que su pagina se tiene que ver en IE7 ó IE8 entonces les recomiendo que las agreguen manualmente ya que pueden tener problemas con el uso de jQuery, ya que hemos agregado las librerias de jQuery a nuestro proyecto debemos de agregar nuestro plugin para su posterior uso. Lo primero que hay que hacer es descargarlo de su sitio (&lt;a href=&quot;http://adf.ly/XIYNy&quot; target=&quot;_blank&quot;&gt;descárgalo de aquí&lt;/a&gt;), ya que lo hemos descargado lo que debemos de hacer es agregar los archivos pqgrid.dev.js y pqgrid.min.js a la carpeta de Scripts y de la misma manera en la carpeta Content agregar pqgrid.dev.css y pqgrid.min.css al igual que las imagenes para el grid, les debe de quedar así.&lt;br /&gt;
 &lt;a href=&quot;http://lh3.ggpht.com/-r27gHIbcUWU/UlcH2AFTV7I/AAAAAAAAAIg/VkPBgRQwKe8/s1600-h/SNAGHTML7c9eaa5%25255B4%25255D.png&quot;&gt;&lt;img alt=&quot;SNAGHTML7c9eaa5&quot; border=&quot;0&quot; height=&quot;344&quot; src=&quot;http://lh4.ggpht.com/-Jn-kr6gMZG8/UlcH3rBixPI/AAAAAAAAAIo/mZO809leoow/SNAGHTML7c9eaa5_thumb%25255B1%25255D.png?imgmax=800&quot; style=&quot;background-image: none; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot; title=&quot;SNAGHTML7c9eaa5&quot; width=&quot;306&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
 Bueno, ya que tenemos listo nuestro proyecto, lo primero que debemos de crear es el modelo de entidades el cual es con el que realizaremos la conexión a nuestro origen de información y por lo consiguiente la extracción de la información.&lt;br /&gt;
 Para este caso lo que vamos a hacer es generar el modelo a partir de una base de datos de la cual queremos mostrar la información, para este tutorial utilizaremos SQL 2008, (&lt;a href=&quot;http://adf.ly/XIXFi&quot; target=&quot;_blank&quot;&gt;aquí&lt;/a&gt; pueden descargar un script para la generación de la Base de Datos que utilizare en el ejemplo) para esto vamos a dar clic derecho sobre la carpeta de Models y vamos a agregar un nuevo item, ahi vamos a seleccionar la en el arbol izq Data y posteriormente ADO.NET Entity Data Model el cual llamaremos TutorialModel y lo agregamos al proyecto.&lt;br /&gt;
 &lt;a href=&quot;http://lh3.ggpht.com/-mKdm6F1r1lE/UlcH4JkPDwI/AAAAAAAAAIw/-Nd8REt7msY/s1600-h/SNAGHTML7e7a378%25255B4%25255D.png&quot;&gt;&lt;img alt=&quot;SNAGHTML7e7a378&quot; border=&quot;0&quot; height=&quot;96&quot; src=&quot;http://lh5.ggpht.com/-V0Eg_182rY4/UlcH4vwj-TI/AAAAAAAAAI4/Pt15VrXFa_4/SNAGHTML7e7a378_thumb%25255B1%25255D.png?imgmax=800&quot; style=&quot;background-image: none; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot; title=&quot;SNAGHTML7e7a378&quot; width=&quot;541&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
 nos preguntara si lo genera vacío o desde la base de datos, nosotros seleccionaremos que lo genere desde la base de datos.&lt;br /&gt;
 &lt;a href=&quot;http://lh3.ggpht.com/-6UEcX-qOw7Y/UlcH5FCbb1I/AAAAAAAAAJA/wobg3kOaOXc/s1600-h/image%25255B7%25255D.png&quot;&gt;&lt;img alt=&quot;image&quot; border=&quot;0&quot; height=&quot;298&quot; src=&quot;http://lh4.ggpht.com/-X68Hp_TRykc/UlcH5qsSV2I/AAAAAAAAAJI/A4wq0UzUsiY/image_thumb%25255B3%25255D.png?imgmax=800&quot; style=&quot;background-image: none; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot; title=&quot;image&quot; width=&quot;481&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
 Ahora realice la configuración de su origen de datos.&lt;br /&gt;
 &lt;a href=&quot;http://lh4.ggpht.com/-ONq54tp37go/UlcH6YBHMJI/AAAAAAAAAJQ/S-hMhnTgWUg/s1600-h/SNAGHTML7ef855e%25255B4%25255D.png&quot;&gt;&lt;img alt=&quot;SNAGHTML7ef855e&quot; border=&quot;0&quot; height=&quot;390&quot; src=&quot;http://lh4.ggpht.com/-KvjYhJBiZ9s/UlcH6wjZP9I/AAAAAAAAAJY/hAsJLfBvYkQ/SNAGHTML7ef855e_thumb%25255B1%25255D.png?imgmax=800&quot; style=&quot;background-image: none; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot; title=&quot;SNAGHTML7ef855e&quot; width=&quot;431&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
 ya que esta configurada haga clic en siguiente y seleccione en el árbol la entrada de Tables y haga clic en Finalizar.&lt;br /&gt;
 &lt;a href=&quot;http://lh4.ggpht.com/-NrsAlTkWzvk/UlcH7qKCw9I/AAAAAAAAAJg/kU2BRplHstQ/s1600-h/image%25255B11%25255D.png&quot;&gt;&lt;img alt=&quot;image&quot; border=&quot;0&quot; height=&quot;332&quot; src=&quot;http://lh4.ggpht.com/-BUjbsaz-1QA/UlcH8LGoeLI/AAAAAAAAAJo/avHfEzk6ckc/image_thumb%25255B5%25255D.png?imgmax=800&quot; style=&quot;background-image: none; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot; title=&quot;image&quot; width=&quot;367&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
 ya hemos creado nuestro modelo de datos para nuestro sitio, y debe de estar viendo algo así:&lt;br /&gt;
 &lt;a href=&quot;http://lh4.ggpht.com/-KuGjfEp1zNQ/UlcH8nZaqBI/AAAAAAAAAJw/jjo_6C0eHsQ/s1600-h/SNAGHTML7f48178%25255B4%25255D.png&quot;&gt;&lt;img alt=&quot;SNAGHTML7f48178&quot; border=&quot;0&quot; height=&quot;248&quot; src=&quot;http://lh6.ggpht.com/-fX_IKzOQ2Bo/UlcH9RlJWSI/AAAAAAAAAJ4/JtoeqYBM2Wg/SNAGHTML7f48178_thumb%25255B1%25255D.png?imgmax=800&quot; style=&quot;background-image: none; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot; title=&quot;SNAGHTML7f48178&quot; width=&quot;513&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
 &lt;br /&gt;
 ya que tenemos nuestro modelo de datos, entonces, a lo que te truje chencha!!!!, vamos a crear nuestra pagina.&lt;br /&gt;
 vamos a crear un controlador y una vista correspondiente el controlador lo llamaremos HOME y a la vista Index, en caso de no saber como hacerlo o como funciona, dejen su mensajito y con gusto hago un Tutorial sobre el uso basico de MVC.&lt;br /&gt;
 Ya que tenemos lista nuestra vista vamos a agregar las referencias a nuestras librerías de jQuery así como al plugin y les debe de quedar mas o menos así:&lt;br /&gt;
&lt;style type=&quot;text/css&quot;&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, &quot;Courier New&quot;, courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;div class=&quot;csharpcode&quot;&gt;&lt;pre class=&quot;alt&quot;&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;../../Scripts/JQuery/jquery-1.10.2.js&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;text/javascript&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&amp;lt;script src=&lt;span class=&quot;str&quot;&gt;&quot;../../Scripts/JQuery/jquery-ui.js&quot;&lt;/span&gt; type=&lt;span class=&quot;str&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/pre&gt;&lt;pre class=&quot;alt&quot;&gt;&amp;lt;script src=&lt;span class=&quot;str&quot;&gt;&quot;../../Scripts/Plugins/Grid/pqgrid.dev.js&quot;&lt;/span&gt; type=&lt;span class=&quot;str&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/pre&gt;&lt;pre&gt;&amp;lt;script src=&lt;span class=&quot;str&quot;&gt;&quot;../../Scripts/Plugins/Grid/pqgrid.min.js&quot;&lt;/span&gt; type=&lt;span class=&quot;str&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt;&amp;gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre class=&quot;alt&quot;&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;link&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;../../Content/themes/base/jquery-ui.css&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;rel&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;stylesheet&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;text/css&quot;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;link&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;../../Content/Plugins/Grid/pqgrid.dev.css&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;rel&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;stylesheet&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;text/css&quot;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre class=&quot;alt&quot;&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;link&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;../../Content/Plugins/Grid/pqgrid.min.css&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;rel&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;stylesheet&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;text/css&quot;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
 &lt;br&gt;este será todo el código que necesitamos por el momento.&lt;br /&gt;
&lt;br /&gt;Vamos a hacer el método de extracción de la información, para esto vamos a ir a nuestro Controlador Home y crearemos el siguiente método.&lt;br /&gt;
&lt;pre class=&quot;csharpcode&quot;&gt;&lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; JsonResult ObtieneClientes() 
        {
            Models.TutorialMVCEntities Context = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; Models.TutorialMVCEntities();
            var _Clientes = Context.Clientes.Select(x =&amp;gt; &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; {Llave = x.ClienteId, Nombre = x.Nombre, ApPaterno = x.apPaterno, ApMaterno = x.apMaterno });
            &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; Json(_Clientes, JsonRequestBehavior.AllowGet);
        }&lt;/pre&gt;
&lt;br /&gt;&lt;style type=&quot;text/css&quot;&gt;.csharpcode, .csharpcode pre&lt;br /&gt;{&lt;br /&gt;	font-size: small;&lt;br /&gt;	color: black;&lt;br /&gt;	font-family: consolas, &quot;Courier New&quot;, courier, monospace;&lt;br /&gt;	background-color: #ffffff;&lt;br /&gt;	/*white-space: pre;*/&lt;br /&gt;}&lt;br /&gt;.csharpcode pre { margin: 0em; }&lt;br /&gt;.csharpcode .rem { color: #008000; }&lt;br /&gt;.csharpcode .kwrd { color: #0000ff; }&lt;br /&gt;.csharpcode .str { color: #006080; }&lt;br /&gt;.csharpcode .op { color: #0000c0; }&lt;br /&gt;.csharpcode .preproc { color: #cc6633; }&lt;br /&gt;.csharpcode .asp { background-color: #ffff00; }&lt;br /&gt;.csharpcode .html { color: #800000; }&lt;br /&gt;.csharpcode .attr { color: #ff0000; }&lt;br /&gt;.csharpcode .alt &lt;br /&gt;{&lt;br /&gt;	background-color: #f4f4f4;&lt;br /&gt;	width: 100%;&lt;br /&gt;	margin: 0em;&lt;br /&gt;}&lt;br /&gt;.csharpcode .lnum { color: #606060; }&lt;br /&gt;&lt;/style&gt;&lt;br /&gt;&lt;br /&gt;esto lo que hace es la extracción desde nuestro modelo a través de una consulta con Linq de la información&amp;nbsp; y la enviamos a la vista formateada como JSON, ahora vamos a crear la llamada y obtención de esta información dentro de la vista con el siguiente código.&lt;br /&gt;
&lt;pre class=&quot;csharpcode&quot;&gt;&amp;lt;script&amp;gt;
    $(document).ready(&lt;span class=&quot;kwrd&quot;&gt;function&lt;/span&gt; () {
        $.ajax({
            type: &lt;span class=&quot;str&quot;&gt;&#39;POST&#39;&lt;/span&gt;,
            url: &lt;span class=&quot;str&quot;&gt;&#39;/Home/ObtieneClientes&#39;&lt;/span&gt;,
            dataType: &lt;span class=&quot;str&quot;&gt;&#39;json&#39;&lt;/span&gt;,
            success: &lt;span class=&quot;kwrd&quot;&gt;function&lt;/span&gt; (data) {
                &lt;span class=&quot;rem&quot;&gt;/*GRID*/&lt;/span&gt;
                obj = { width: 700, height: 400, title: &lt;span class=&quot;str&quot;&gt;&quot;Información de Clientes&quot;&lt;/span&gt;, flexHeight: &lt;span class=&quot;kwrd&quot;&gt;true&lt;/span&gt; };
                &lt;span class=&quot;rem&quot;&gt;//Vamos a definir el modelo de columnas para nuestro Grid&lt;/span&gt;
                obj.colModel = [{ title: &lt;span class=&quot;str&quot;&gt;&quot;Id&quot;&lt;/span&gt;, width: 100, dataType: &lt;span class=&quot;str&quot;&gt;&quot;integer&quot;&lt;/span&gt;, dataIndx: &lt;span class=&quot;str&quot;&gt;&quot;Llave&quot;&lt;/span&gt; },
                                                  { title: &lt;span class=&quot;str&quot;&gt;&quot;Nombre del Cliente&quot;&lt;/span&gt;, width: 200, dataType: &lt;span class=&quot;str&quot;&gt;&quot;string&quot;&lt;/span&gt;, dataIndx: &lt;span class=&quot;str&quot;&gt;&quot;Nombre&quot;&lt;/span&gt; },
                                                  { title: &lt;span class=&quot;str&quot;&gt;&quot;Ap. Paterno&quot;&lt;/span&gt;, width: 200, dataType: &lt;span class=&quot;str&quot;&gt;&quot;string&quot;&lt;/span&gt;, dataIndx: &lt;span class=&quot;str&quot;&gt;&quot;ApPaterno&quot;&lt;/span&gt; },
                                                  { title: &lt;span class=&quot;str&quot;&gt;&quot;Ap. Materno&quot;&lt;/span&gt;, width: 200, dataType: &lt;span class=&quot;str&quot;&gt;&quot;string&quot;&lt;/span&gt;, dataIndx: &lt;span class=&quot;str&quot;&gt;&quot;ApMaterno&quot;&lt;/span&gt;}];
                obj.dataModel = {
                    data: data,
                    location: &lt;span class=&quot;str&quot;&gt;&quot;local&quot;&lt;/span&gt;,
                    sorting: &lt;span class=&quot;str&quot;&gt;&quot;local&quot;&lt;/span&gt;,
                    paging: &lt;span class=&quot;str&quot;&gt;&quot;local&quot;&lt;/span&gt;,
                    curPage: 1,
                    rPP: 20,
                    sortIndx: &lt;span class=&quot;str&quot;&gt;&quot;Llave&quot;&lt;/span&gt;,
                    sortDir: &lt;span class=&quot;str&quot;&gt;&quot;up&quot;&lt;/span&gt;,
                    rPPOptions: [1, 10, 20, 30, 40, 50, 100, 500, 1000]
                };
                &lt;span class=&quot;rem&quot;&gt;/*GRID*/&lt;/span&gt;
            },
            error: &lt;span class=&quot;kwrd&quot;&gt;function&lt;/span&gt; (xhr, ajaxOptions, error) {
                alert(xhr.status);
                alert(&lt;span class=&quot;str&quot;&gt;&#39;Error: &#39;&lt;/span&gt; + xhr.responseText);
            },
            complete: &lt;span class=&quot;kwrd&quot;&gt;function&lt;/span&gt; () { &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; $grid = $(&lt;span class=&quot;str&quot;&gt;&quot;#Datos&quot;&lt;/span&gt;).pqGrid(obj); }
        });
    });
&amp;lt;/script&amp;gt;&lt;/pre&gt;
&lt;br /&gt;&lt;br /&gt;&lt;style type=&quot;text/css&quot;&gt;.csharpcode, .csharpcode pre&lt;br /&gt;{&lt;br /&gt;	font-size: small;&lt;br /&gt;	color: black;&lt;br /&gt;	font-family: consolas, &quot;Courier New&quot;, courier, monospace;&lt;br /&gt;	background-color: #ffffff;&lt;br /&gt;	/*white-space: pre;*/&lt;br /&gt;}&lt;br /&gt;.csharpcode pre { margin: 0em; }&lt;br /&gt;.csharpcode .rem { color: #008000; }&lt;br /&gt;.csharpcode .kwrd { color: #0000ff; }&lt;br /&gt;.csharpcode .str { color: #006080; }&lt;br /&gt;.csharpcode .op { color: #0000c0; }&lt;br /&gt;.csharpcode .preproc { color: #cc6633; }&lt;br /&gt;.csharpcode .asp { background-color: #ffff00; }&lt;br /&gt;.csharpcode .html { color: #800000; }&lt;br /&gt;.csharpcode .attr { color: #ff0000; }&lt;br /&gt;.csharpcode .alt &lt;br /&gt;{&lt;br /&gt;	background-color: #f4f4f4;&lt;br /&gt;	width: 100%;&lt;br /&gt;	margin: 0em;&lt;br /&gt;}&lt;br /&gt;.csharpcode .lnum { color: #606060; }&lt;br /&gt;&lt;/style&gt;&lt;br /&gt;y con esto terminamos ahora a ver el resultado.&lt;br /&gt;
&lt;br /&gt;&lt;a href=&quot;http://lh3.ggpht.com/-mT831azIK64/UlcH9yQI9JI/AAAAAAAAAKA/17JNJKxh_WU/s1600-h/SNAGHTML8175b05%25255B6%25255D.png&quot;&gt;&lt;img alt=&quot;SNAGHTML8175b05&quot; border=&quot;0&quot; height=&quot;384&quot; src=&quot;http://lh6.ggpht.com/-pnMUc-qjjgg/UlcH-cyFULI/AAAAAAAAAKI/zpWQnbzLjhA/SNAGHTML8175b05_thumb%25255B9%25255D.png?imgmax=800&quot; style=&quot;background-image: none; border-bottom: 0px; border-left: 0px; border-right: 0px; border-top: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot; title=&quot;SNAGHTML8175b05&quot; width=&quot;487&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;y bueno con esto finalizo esta entrada esperando que les haya sido de utilidad.&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://quoacademico.blogspot.com/feeds/7333658217494487267/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://quoacademico.blogspot.com/2013/10/como-mostrar-datos-con-aspnet-mvc-4-y.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2134748813367998500/posts/default/7333658217494487267'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2134748813367998500/posts/default/7333658217494487267'/><link rel='alternate' type='text/html' href='http://quoacademico.blogspot.com/2013/10/como-mostrar-datos-con-aspnet-mvc-4-y.html' title='Como: Mostrar datos con ASP.NET MVC 4 y Entity Framework'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16735065261569552657</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh4.ggpht.com/-ONFy4kKN6_g/UlcH0ltO5gI/AAAAAAAAAII/s3mpvZXm7RU/s72-c/SNAGHTML7b11424_thumb%25255B1%25255D.png?imgmax=800" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2134748813367998500.post-7152655409940729193</id><published>2013-10-10T08:24:00.000-07:00</published><updated>2015-02-24T11:32:01.555-08:00</updated><title type='text'></title><content type='html'>&lt;script type=&quot;text/javascript&quot;&gt;
$(document).ready(function(){
        $(&quot;.Boton&quot;).button().click(function(){alert(&quot;Hola jQuery!!!!&quot;);$(&quot;.dialog-modal&quot;).dialog(&quot;open&quot;);});
$( &quot;.dialog-modal&quot; ).dialog({
      height: 140,
      modal: true,
      autoOpen: false
    });
});
&lt;/script&gt;
&lt;a class=&quot;Boton&quot;&gt;Prueba &lt;/a&gt;
&lt;div class=&quot;dialog-modal&quot;&gt;Hola&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://quoacademico.blogspot.com/feeds/7152655409940729193/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://quoacademico.blogspot.com/2013/10/document.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2134748813367998500/posts/default/7152655409940729193'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2134748813367998500/posts/default/7152655409940729193'/><link rel='alternate' type='text/html' href='http://quoacademico.blogspot.com/2013/10/document.html' title=''/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16735065261569552657</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2134748813367998500.post-2558106349598227186</id><published>2009-12-25T07:01:00.001-08:00</published><updated>2010-09-23T12:37:05.918-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="SQL"/><title type='text'>Tamaño de Tablas dentro de una Base de Datos de SQL</title><content type='html'>&lt;p&gt;Saludos!!!!!!&lt;/p&gt;  &lt;p&gt;   &lt;p&gt;Cuantas veces no nos hemos encontrado con el dilema de que necesitamos saber cuanto espacio esta ocupando nuestras tablas dentro de la base de datos de &lt;a href=&quot;http://es.wikipedia.org/wiki/SQL&quot;&gt;SQL&lt;/a&gt;, esto normalmente con el fin de realizar un informe para dar cuentas de la información que se esta cargando ó quizá para realizar un estimado de crecimiento de la base de datos, o yo que se, para algo …..&amp;#160; así que por estas y muchas cosas mas aquí les dejo una funcioncita no documentada de SQL que ejecutándolo en un Analizador de Consultas nos podrá dar la información que requerimos, espero que les ayude a que les sea mas leve. &lt;/p&gt;    &lt;p&gt;&lt;/p&gt; &lt;/p&gt;  &lt;p&gt;   &lt;p&gt;&lt;strong&gt;&lt;em&gt;sp_MSForEachtable &#39;sp_spaceused &#39;&#39;?&#39;&#39;&#39;&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;    &lt;p&gt;&lt;/p&gt; &lt;/p&gt;  &lt;p&gt;   &lt;p&gt;o También pueden ejecutar esta otra a ver cual les sirve mas…&lt;/p&gt;    &lt;p&gt;&lt;/p&gt; &lt;/p&gt;  &lt;p&gt;   &lt;p&gt;&lt;strong&gt;&lt;em&gt;SELECT SI.[rows] as &#39;Filas&#39;, SO.[Name] as Tabla, SI.[name] as &#39;Index&#39;, SFG.[groupname] as &#39;Filegroup&#39;&amp;#160; &lt;br /&gt;FROM sysobjects as SO           &lt;br /&gt;JOIN sysindexes as SI ON SO.[Id] = SI.[id]           &lt;br /&gt;JOIN sysfilegroups as SFG ON SI.[GroupId] = SFG.GroupId           &lt;br /&gt;ORDER BY si.[rows] DESC, SO.[Name] , SI.[name], SFG.[GroupName]&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;    &lt;p&gt;&lt;/p&gt; &lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;http://images.google.com.mx/imgres?imgurl=http://javierleal.files.wordpress.com/2009/08/sql-server-2005-2.jpg&amp;amp;imgrefurl=http://javierleal.wordpress.com/2009/08/23/acceso-a-datos-con-visual-basic-net/&amp;amp;usg=__EUXcNIwxofX6LBI-kTSWHz6ZSTg=&amp;amp;h=230&amp;amp;w=230&amp;amp;sz=31&amp;amp;hl=es&amp;amp;start=3&amp;amp;um=1&amp;amp;tbnid=zXwLBdPOQw9XuM:&amp;amp;tbnh=108&amp;amp;tbnw=108&amp;amp;prev=/images%3Fq%3DSQL%2B2005%26hl%3Des%26sa%3DN%26um%3D1&quot;&gt;&lt;img style=&quot;display: block; float: none; margin-left: auto; margin-right: auto&quot; src=&quot;http://t3.gstatic.com/images?q=tbn:zXwLBdPOQw9XuM:http://javierleal.files.wordpress.com/2009/08/sql-server-2005-2.jpg&quot; width=&quot;108&quot; height=&quot;108&quot; /&gt;&lt;/a&gt;&lt;/p&gt;  </content><link rel='replies' type='application/atom+xml' href='http://quoacademico.blogspot.com/feeds/2558106349598227186/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://quoacademico.blogspot.com/2009/12/tamano-de-tablas-dentro-de-una-base-de.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2134748813367998500/posts/default/2558106349598227186'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2134748813367998500/posts/default/2558106349598227186'/><link rel='alternate' type='text/html' href='http://quoacademico.blogspot.com/2009/12/tamano-de-tablas-dentro-de-una-base-de.html' title='Tamaño de Tablas dentro de una Base de Datos de SQL'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16735065261569552657</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2134748813367998500.post-4713426348748367198</id><published>2009-12-18T13:31:00.001-08:00</published><updated>2010-09-23T12:37:05.918-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="SQL"/><title type='text'>No dudes en preguntar…..</title><content type='html'>&lt;p&gt;   &lt;p&gt;     &lt;p&gt;Siempre que nos encontramos en la escuela o en algún lugar tomando un curso o yo que se en cualquier lugar, siempre nos da pena preguntar debido al “que dirán si pregunto esa tontería….”, sin embargo creo que mucho del aprendizaje que se obtiene es preguntando por lo que me gustaría que si tienen alguna duda con respecto a SQL; VB.NET, C#, WPF, no duden en preguntar.&lt;/p&gt;&lt;/p&gt;&lt;/p&gt;  </content><link rel='replies' type='application/atom+xml' href='http://quoacademico.blogspot.com/feeds/4713426348748367198/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://quoacademico.blogspot.com/2009/12/no-dudes-en-preguntar.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2134748813367998500/posts/default/4713426348748367198'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2134748813367998500/posts/default/4713426348748367198'/><link rel='alternate' type='text/html' href='http://quoacademico.blogspot.com/2009/12/no-dudes-en-preguntar.html' title='No dudes en preguntar…..'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16735065261569552657</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>