Skip to main content

How To Call An Action In a Controller From A dropdown change event

By Using MVC4 ,JQuery,And Nhibernate

sample Code



//Script Block
    $(function () {
        $("#resourceSelectList").change(function () {
            var urlAction = "~/Planner/LoadPlannerWithFilter?value=";
            var value = $(this).val();

    
        });
    });


@*HTML Markup*@

 @Html.DropDownListFor(x => x.resourceSelectList, Model.resourceSelectList)
 
 
And Cotroller Part
 

        public ActionResult PlannerLanding()
        {
            WrapperClass wrp = new WrapperClass();
            var resourceSelectList = obj.getResourceList()
                                        .Select(x => new SelectListItem
                                        {
                                            Value = x.Owner,
                                            Text = x.Owner
                                        });
            wrp.resourceSelectList = new SelectList(resourceSelectList, 
   "Value", "Text");
            return View(wrp);
        }

/*
*This action method is getting called when the drop down value changes.  
*/

        public ActionResult LoadPlannerWithFilter(string value)
        {
            WrapperClass wrp = new WrapperClass();
            var resourceSelectList = obj.getResourceList()
                                        .Select(x => new SelectListItem
                                        {
                                            Value = x.Owner,
                                            Text = x.Owner
                                        });
            wrp.resourceSelectList = new SelectList(resourceSelectList, 
              "Value", "Text");
            return View("PlannerLanding",wrp);
        }  

Comments

Popular posts from this blog

NHibernate QueryOver Class And Projection....

Introduction The ICriteria API is NHibernate's implementation of Query Object . NHibernate 3.0 introduces the QueryOver api, which combines the use of Extension Methods and Lambda Expressions (both new in .Net 3.5) to provide a statically typesafe wrapper round the ICriteria API. QueryOver uses Lambda Expressions to provide some extra syntax to remove the 'magic strings' from your ICriteria queries. So, for example: .Add(Expression.Eq("Name", "Smith")) becomes: .Where<Person>(p => p.Name == "Smith") With this kind of syntax there are no 'magic strings', and refactoring tools like 'Find All References', and 'Refactor->Rename' work perfectly. Note: QueryOver is intended to remove the references to 'magic strings' from the ICriteria API while maintaining it's opaqueness. It is not a LINQ provider; NHibernate 3.0 has a built-in ...

Passing Data from View to Controller Using Ajax Example Jquery

Jquery       $ ( '#btnSaveComments' ). click ( function () { var comments = $ ( '#txtComments' ). val (); var selectedId = $ ( '#hdnSelectedId' ). val (); $ . ajax ({ url : '<%: Url.Action("SaveComments")%>' , data : { 'id' : selectedId , 'comments' : comments }, type : "post" , cache : false , success : function ( savingStatus ) { $ ( "#hdnOrigComments" ). val ( $ ( '#txtComments' ). val ()); $ ( '#lblCommentsNotification' ). text ( savingStatus ); }, error : function ( xhr , ajaxOptions , thrownError ) { $ ( '#lblCommentsNotification' ). text ( "Error encountered while saving the comments." ); } }); });     Controller    [ HttpPost ] public ActionResult SaveComments ( int id , string com...

Understanding machine learning

What is machine learning does?  It Finds patterns in data and uses those patterns to predict the future.          EXAMPLES :  Detecting credit card fraud : You can use machine learning  detect credit card fraud, Suppose you have data about previous credit card transactions. You could find patterns in that data potentially  that allows you to detect when a new credit card transaction is likely to be fraudulent. Determining whether a customer is likely to switch to a competitor :  You could possibly find the patterns in the existing customer data that will help you do that Lots more What does it mean to learn ? Yes it's something like your own learning process. You have learned reading,listening, walking everything by using your experience on it, the data you have in your mind and continuous improvements.  How did you learn to read? Well learning requires identifying patterns. Reading for instance you ...