1 Frist you have make the Controller and make the two table in database.
2 Name the table in database and you have make the folder in the name of database.
3 you have import the database in the Controller
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using practice12.database;
using practice12.Controllers;
using practice12.Models;
namespace practice12.Controllers
{
public class HomeController : Controller
{
private readonly AMSEntities db = new AMSEntities();
// GET: Home
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Lahore (string src)
{
ModelView model = new ModelView();
if (!string.IsNullOrEmpty(src))
{
model.scl = db.SchoolLocations.Where(b => b.SchoolName.Contains(src)).ToList();
model.tea = db.Teachers.Where(b => b.TeacherName.Contains(src)).ToList();
}
return View(model);
}
}
}
----------------------------------------------------------------------------------------------------------------------------
<----- Model Class----->
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using practice12.database;
using practice12.Controllers;
namespace practice12.Models
{
public class ModelView
{
public IEnumerable<SchoolLocation> scl { get; set; }
public IEnumerable<Teacher> tea { get; set; }
}
}
---------------------------------------------------------------------------------------------------------------------------
<--------Index------>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
@using (Html.BeginForm("Lahore", "Home", FormMethod.Post))
{
<div>
<input type="text" name="src" id="src" class="form-control" />
<input type="submit" value="sub" class="btn btn-danger" />
</div>
}
-------------------------------------------------------------------------------------------------------------------------
<--------------------------Lahore----------------------------------------------->
@model practice12.Models.ModelView
@using (Html.BeginForm("Lahore", "Home", FormMethod.Post))
{
<div>
<input type="text" name="src" id="src" class="form-control" />
<input type="submit" value="sub" class="btn btn-danger" />
</div>
}
<div>School</div>
<div>
@foreach (var item in Model.scl)
{
<div>
<p>
@item.SchoolName;
</p>
</div>
}
</div>
Teacher
<div>
@foreach (var item in Model.tea)
{
<div>
<p>
@item.TeacherName;
</p>
</div>
}
</div>