Ejemplo n.º 1
0
        //AJAX

        public PartialViewResult Testimonial_Search(FormCollection form)
        {
            _Testimonial testimonial_list = new _Testimonial();
            string       search_term      = form["term"];

            if (!String.IsNullOrWhiteSpace(search_term))
            {
                try
                {
                    // These doesn't work
                    //testimonial_list.Contents = db.Testimonials.Where(t => t.Content.ToLower().Contains(search_term.ToLower())).ToList();
                    //testimonial_list.Subjects = db.Testimonials.Where(t => t.Subject.ToLower().Contains(search_term.ToLower())).ToList();

                    // This works
                    List <Testimonial> testimonial = db.Testimonials.Where(t => t.Content.ToLower().Contains(search_term.ToLower())).ToList();
                    ViewBag.Count = testimonial.Count;

                    //the result is stored in testimonial_list but it doesn't go to the partial view
                    return(PartialView("_Testimonials", testimonial));
                }
                catch (Exception genericException)
                {
                    ViewBag.ExceptionMessage = genericException.Message;
                }
                return(PartialView("~/Views/Errors/_Details.cshtml"));
            }
            return(PartialView("~/Views/Testimonial/_Testimonials.cshtml", testimonial_list));
        }
Ejemplo n.º 2
0
        public PartialViewResult Testimonial_Search_Admin(FormCollection form)
        {
            _Testimonial testimonial_list = new _Testimonial();
            string       search_term      = form["term"];

            if (!String.IsNullOrWhiteSpace(search_term))
            {
                try
                {
                    List <Testimonial> testimonial = db.Testimonials.Where(t => t.Content.ToLower().Contains(search_term.ToLower())).ToList();
                    ViewBag.Count = testimonial.Count;
                    return(PartialView("_Testimonials_Admin", testimonial));
                }
                catch (Exception genericException)
                {
                    ViewBag.ExceptionMessage = genericException.Message;
                }
                return(PartialView("~/Views/Errors/_Details.cshtml"));
            }
            return(PartialView("~/Views/Testimonial/_Testimonials_Admin.cshtml", testimonial_list));
        }