如何在MVC4中做sql? [英] HOW to do sql in MVC4 ?
本文介绍了如何在MVC4中做sql?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
实际上更新的IT,这是我的sql server查询..我需要在我的项目MVC上实现...你可以解释或指导我如何在mvc中做到这一点??
SQL语句
Actual am fresher in I.T, This is my sql server query.. i need to implement on my project MVC ... can u explain or guide me how to do this in mvc ??
SQL statement
select *
from tblBusinessCategory as b
inner join tblUser as u on b.BusinessID=u.BusinessCategoryId
inner join tblAddress as a on u.AddressId=a.AddressID
where b.BusinessCategory LIKE '%keyword%' or b.BusinessName LIKE '%keyword%'
我的控制器:
My controller:
public ActionResult Index(string txtValue)
{
var s = txtValue.ToString();
Session["searched"] = s;
if (txtValue.Length > 0)
{
string[] keywords = txtValue.Trim().Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
return View(list);
}
else
{
ViewBag.Message = true;
return View();
}
}
查看:
View:
<div class="searchform cf">
@using (Html.BeginForm())
{
<input type="text" name="txtValue" id="txtValue" value="@Session["searched"]" placeholder="Need more ?">
<button type="submit" value="Search" style="margin-top: 5px;">Search</button>
}
</div>
<div style="margin: 35px 0px 0px 90px">
@if (ViewBag.Message == true)
{
<label id="lblMessage" title="Please enter keyword" style="color:red;">Please enter keyword...!</label>
}
else
{
if (Model != null)
{
if (Model.Count() != 0)
{
<div>
<h2 style="font-size: 15px;">Searched for "<i style=" padding: 0px 10px; color: #595FFF;">@Session["searched"]</i>"</h2>
</div>
<div>
@foreach (var item in Model)
{
<b style="margin-left: -8px; font-size: large;color: #2B9CE2;">
@Ajax.ActionLink(@item.bName, "Businessdetails", "Search", new { id = item.bID }, null)
</b>
<div class="hover">
test
</div>
<h3 style="margin: 0px;">@item.bCategory</h3>
}
</div>
}
else
{
<label id="lblErrorMsg" title="Record not fount...!" style="color:red;">Record not found...!</label>
}
}
}
推荐答案
你问了几个相似问题 [ ^ ]。我强烈建议阅读所有答案。请从基础开始 - 阅读文档 [< a href =https://msdn.microsoft.com/en-us/library/dd381412%28v=vs.108%29.aspxtarget =_ blanktitle =New Window> ^ ] !当你遇到困难时回到这里。
You had asked few similar questions[^]. I do strongly suggest to read all answers. And please, start with basics - read a documentation[^]! Come back here when you get stuck.
这篇关于如何在MVC4中做sql?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文