Wednesday, April 10, 2013

How to get/set Selected Values of Select2 Multi Selection List in MVC?

Hi 
Here  you  can  get  selected element of  Multi selection list  using  Select2 Jqyery.

Jquery Code

var AuthorList=  $("select#AuthorList").select2("val");
-----------------------------------------------------------------------

2. How to set MultiSelection List?

    First  Get  Selected  value  from  your  database  and  add  into   Hidden Field
like.



Then
Var authlist="";
  var a_options = [];

        $.each($("#AuthorListoption"), function () {
            if (authlist.toLowerCase().indexOf($(this).attr("value")) >= 0) {
                a_options.push($(this).attr("value"));
            }

        });

        $("select#AuthorList").select2("val", a_authlist);

HAPPY CODING



How To Bind MultiSelection List with Select2 Jquery in MVC

Action
------------------
Public ActionResult Author()
{
     SelectList AuthorList= null;
            IEnumerable Author = AuthorList.AsEnumerable().Select(c => new SelectListItem()

           {
               Text = objauth.ReplaceTagValueToTerm(c.TagValue, c.Term),
               Value = c.Id.ToString(),
               Selected = true,
           });
           Newterms = new SelectList(Author, "Value", "Text");
            ViewBag.AuthorList= Newterms;
}
}

-------------------------------------------------------------------------------------
View Page
     @Html.DropDownList("infoTypes", (SelectList)ViewData["AuthorList"], new { @class = "NewCssdropdown", multiple = "" })
---------------------------------------------------------------------
Jquery

  $("#AuthorList").select2(
        {
            maximumSelectionSize: 4 //  Here You can define maximum selection


        });


HAPPY CODING

How to Bind Select2 Jquery in MVC

Action
------------------
Public ActionResult Author()
{
     SelectList Newterms = null;
            IEnumerable Author = AuthorList.AsEnumerable().Select(c => new SelectListItem()

           {
               Text = objauth.ReplaceTagValueToTerm(c.TagValue, c.Term),
               Value = c.Id.ToString(),
               Selected = true,
           });
           Newterms = new SelectList(Author, "Value", "Text");
            ViewBag.NewTerms = Newterms;

}
}

-------------------------------------------------------------------------------------
View Page
    @Html.DropDownList("NewTerms", (SelectList)ViewData["NewTerms"], new { @class = "NewCssdropdown" })


--------------------------------------------------------------------------------------
Jquery


---------------------------------------------------------------------------------------------





HAPPY CODING

How to get selected Value from Select2 Jquery.

Hi To know how to bind Dropdown using Select2. Please reffer  my  old  Post

How To Bind Select2

Now i  will  give you  one example to Get Selected Value.


Jquery
--------
  var AuthorList= $("#AuthorList").val();

HAPPY CODING

Wednesday, July 25, 2012

CS0012: The type 'System.Data.Objects.DataClasses.EntityObject' is defined in an assembly that is not referenced.

When  using  Entity frame work . passing  the  data  with control i got  one error 

"Compiler Error Message: CS0012: The type 'System.Data.Objects.DataClasses.EntityObject' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'."

After  R & D  i  found  solution. so  i  am  posting  this  solutions because i don't  want  to  waste  your lot  of  time like as  i  did.

here  is  solution type following code  in  your web config  file  


" "

Thanks  Happy Coding

Tuesday, July 17, 2012

Hide/Show Div With Smooth Effect.

Hi  i am  giving you  one example to show  and hide  div with smooth effect .

My html Code:

<div id="done" style="display:none;">
write content here
</div>
My Java Script Code
<script>

 $('#done').fadeIn('slow');

                setTimeout(function () {
                    $('#done').fadeOut('slow');
                }, 2000);
</script>








Happy  Coding

Wednesday, July 11, 2012

How to Define action Link Using Areas In MVC

Hi..

I  am  giving  one example to  define Action Link Url Using Multiple Areas..

I am  using two areas with Name
a) Control
b) System
.

 
  • @Html.ActionLink("Main Home", "Index", "Home", new { Area = "" }, null)

  •  
  • @Html.ActionLink(" Control Home", "Index", "ControlHome", new { Area = "Control" }, null)

  •  
  • @Html.ActionLink(" System Home", "Index", "SystemHome", new { Area = "System" }, null)





  • Happy  Coding