[Solved] Return data from the database instead of api [closed]


In Controller:
Make sure you created and inherited DbContext in model and also added Dbset of your
table to it.

    public ActionResult getFromDataBase()
    {
       // create object for your context of Database
        var studentContext = new studentContext();
       // return tablename data you want to retrieve in view
        return View(studentContext.TableName.ToList());

    }

In View:
First import model
@model ProjectName.Models.TableName //e.g Demo.Models.StudentMaster

    //Now you can access any content using HTML tag helpers with loop or condition in view

    //e.g. Html.TextboxFor(model=>model.FieldName)

solved Return data from the database instead of api [closed]