wademi
asked on
C# MVC help:LINQ to SQL
I am learning MVC using C# and need help with linq to sql
I have a controller that lookslike this:
using System;
using System.Collections.Generic ;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using VTask.Models;
namespace VTask.Controllers
{
public class SitesController : Controller
{
//
// GET: /Sites/
SiteRepository siterepository = new SiteRepository();
public ActionResult Index()
{
var mysites = siterepository.FindAllSite s().ToList ();
return View("Index", mysites);
}
[AcceptVerbs(HttpVerbs.Pos t)]
public ActionResult Search(string Search)
{
var matchingsites = siterepository.Findmatchin gsites(Sea rch).ToLis t();
return View("Index", matchingsites);
}
}
}
My Model has a siterepository.cs that looks like this:
using System;
using System.Collections.Generic ;
using System.Linq;
using System.Web;
namespace VTask.Models
{
public class SiteRepository
{
private SitesDataContext dbx = new SitesDataContext();
public IQueryable<V_Site> FindAllSites()
{
return dbx.V_Sites;
}
public IQueryable<V_Site> Findmatchingsites(string macthcsite)
{
return from siteslike in dbx.V_Sites
where siteslike.Server.Contains( macthcsite )
select siteslike;
}
}
}
I would like like to be able to click on the search button in the screenshot and and get results from my database.
When I click on the search button(Findmatchingsites) nothing happens.
Is the LINQ to SQL syntax correct? What am I doing wrong here?
Here is a part of my Views->Sites Index.aspx
<h2>Index</h2>
<label for="Search server">Search:</label>
<%= Html.TextBox("Search") %>
<button class="okButton" type="submit" value="Search" >Search</button>
I have a controller that lookslike this:
using System;
using System.Collections.Generic
using System.Linq;
using System.Web;
using System.Web.Mvc;
using VTask.Models;
namespace VTask.Controllers
{
public class SitesController : Controller
{
//
// GET: /Sites/
SiteRepository siterepository = new SiteRepository();
public ActionResult Index()
{
var mysites = siterepository.FindAllSite
return View("Index", mysites);
}
[AcceptVerbs(HttpVerbs.Pos
public ActionResult Search(string Search)
{
var matchingsites = siterepository.Findmatchin
return View("Index", matchingsites);
}
}
}
My Model has a siterepository.cs that looks like this:
using System;
using System.Collections.Generic
using System.Linq;
using System.Web;
namespace VTask.Models
{
public class SiteRepository
{
private SitesDataContext dbx = new SitesDataContext();
public IQueryable<V_Site> FindAllSites()
{
return dbx.V_Sites;
}
public IQueryable<V_Site> Findmatchingsites(string macthcsite)
{
return from siteslike in dbx.V_Sites
where siteslike.Server.Contains(
select siteslike;
}
}
}
I would like like to be able to click on the search button in the screenshot and and get results from my database.
When I click on the search button(Findmatchingsites) nothing happens.
Is the LINQ to SQL syntax correct? What am I doing wrong here?
Here is a part of my Views->Sites Index.aspx
<h2>Index</h2>
<label for="Search server">Search:</label>
<%= Html.TextBox("Search") %>
<button class="okButton" type="submit" value="Search" >Search</button>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
[AcceptVerbs(HttpVerbs.Pos t)]
public ActionResult Index(string Search)
{
var matchingsites = siterepository.Findmatchin gsites(Sea rch).ToLis t();
return View("Index", matchingsites);
}
public ActionResult Index(string Search)
{
var matchingsites = siterepository.Findmatchin
return View("Index", matchingsites);
}
ASKER