Gopi

Gopi

  • 1.4k
  • 305
  • 20.8k

Controller not returning a view

Dec 19 2022 3:50 AM

This ajax works fine but the controller does not return the view. It returns either blank view or returns inappropriate View. How can I solve this issue.

 Getprojectsbylocation(int state_id)
        {
            var ds = _dal.Getprojectsbylocation(state_id);
            var dt = ds.Tables[0];
            List<Projects> li = new List<Projects>();
            li = Helper.ConvertDataTable<Projects>(dt);           
            return View();
        }

My controller code:

public IActionResult Getprojectsbylocation(int state_id)
        {
            var ds = _dal.Getprojectsbylocation(state_id);
            var dt = ds.Tables[0];
            List<Projects> li = new List<Projects>();
            li = Helper.ConvertDataTable<Projects>(dt);           
            return View();
        }

Ajax call:

 $('#button').click(function () {
            $.ajax({
                url: "/Company/Getprojectsbylocation",
                type: "get",
                dataType: "application/ json; charset = utf-8",
                data: { state_id: $("#txtstateId").val() }

            })
        });

 


Answers (3)