// Adding
[HttpPost]
public ActionResult Mailus(tbl_Query tblQuery)
{
using (LetslukdbEntities entities = new LetslukdbEntities())
{
entities.tbl_Query.Add(tblQuery);
entities.SaveChanges();
}
return View();
}
// Listing
public ActionResult List()
{
using (LetslukdbEntities entities = new LetslukdbEntities())
{
return View(entities.tbl_Query.ToList());
}
}
// Editing or Updating Get
public ActionResult Edit(int id)
{
using (LetslukdbEntities entities = new LetslukdbEntities())
{
var Querydata = entities.tbl_Query.Where(x => x.QueryID == id).FirstOrDefault();
if (Querydata != null)
{
TempData["QueryID"] = id;
TempData.Keep();
return View(Querydata);
}
return View();
}
}
// Editing or Updating Post
[HttpPost]
public ActionResult Edit(tbl_Query objQuery)
{
using (LetslukdbEntities entities = new LetslukdbEntities())
{
Int32 id = (int)TempData["QueryID"];
var Querydata = entities.tbl_Query.Where(x => x.QueryID == id).FirstOrDefault();
if (Querydata != null)
{
Querydata.Name = objQuery.Name;
Querydata.Email = objQuery.Email;
Querydata.Phone = objQuery.Phone;
Querydata.Query = objQuery.Query;
entities.Entry(Querydata).State = EntityState.Modified;
entities.SaveChanges();
}
return View();
}
}
// Delete
public ActionResult Delete(int id)
{
using (LetslukdbEntities entities = new LetslukdbEntities())
{
var Querydata = entities.tbl_Query.Where(x => x.QueryID == id).FirstOrDefault();
if (Querydata != null)
{
entities.Entry(Querydata).State = EntityState.Deleted;
entities.SaveChanges();
}
return RedirectToAction("List");
}
}
In Views
Add:
@model SantechDataAccess.tbl_Query
@{
ViewBag.Title = "Customer Review : Santech Info Services";
Layout = "~/Views/Shared/_LayoutSantech.cshtml";
}
<!-- banner -->
<div class="div_bannerContent">
<p>Mail Us</p>
</div>
<!--//banner -->
<!--/w3_short-->
<div class="div_breadcrum">
<div class="div_breadcrumIn">
<ul class="short">
<li><a href="www.santechinfoservices.com">Home</a><span>|</span></li>
<li>Mail Us</li>
</ul>
</div>
</div>
<!--//w3_short-->
<!-- /features -->
<div class="banner-bottom">
<div class="container">
<div class="div_titleHead">
<h3 class="tittle">Mail <span>Us</span></h3>
<div class="row">
<div class="col-md-12">
<h3>If you have any query, Feel free to write us at <u>infoletsluk@gmail.com</u> or fill form to contact us.
</h3>
</div> <div class="row">
<div class="col-md-7 col-sm-7">
<div class="div_careerform">
@using (Html.BeginForm("Mailus", "Company", FormMethod.Post))
{
@*<asp:Label ID="lbl_msg" runat="server" Text="" Visible="false"></asp:Label>*@
<div class="col-md-6 col-sm-6 paddingLeftNone10">
<div class="div_inputCareer">
<input id="txt_name" name ="Name" placeholder="Name" class="form-control" runat="server" />
</div>
</div>
<div class="col-md-6 col-sm-6 paddingLeftNone10">
<div class="div_inputCareer">
<input id="txt_email" name="Email" placeholder="Email-id" class="form-control" runat="server" />
</div>
</div>
<div class="col-md-12 col-sm-12 paddingLeftNone10">
<div class="div_inputCareer">
<input id="txt_phone" name="Phone" placeholder="Mobile No." class="form-control" runat="server">
</div>
</div>
<div class="col-md-12 col-sm-12 paddingLeftNone10">
<div class="form-group">
<input id="txt_Query" name="Query" placeholder="Write your message here" class="form-control" runat="server" textmode="MultiLine">
</div>
</div>
<div class="col-md-12 col-sm-12 paddingLeftNone10">
<input id="btnSubmit" type="submit" class="btn btn-info" runat="server" text="Submit" />
</div>
}
</div>
</div>
<div class="col-md-5 col-sm-5">
</div></div>
</div>
</div>
</div>
</div>
<!-- //features -->
@model IEnumerable<SantechDataAccess.tbl_Query>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>@Html.DisplayNameFor(model => model.Name)
</th>
<th>@Html.DisplayNameFor(model => model.Email)
</th>
<th>@Html.DisplayNameFor(model => model.Phone)
</th>
<th>@Html.DisplayNameFor(model => model.Query)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>@Html.DisplayFor(modelItem => item.Name)
</td>
<td>@Html.DisplayFor(modelItem => item.Email)
</td>
<td>@Html.DisplayFor(modelItem => item.Phone)
</td>
<td>@Html.DisplayFor(modelItem => item.Query)
</td>
<td>@Html.ActionLink("Edit", "Edit", new { id=item.QueryID }) |
@Html.ActionLink("Details", "Details", new { id=item.QueryID }) |
@Html.ActionLink("Delete", "Delete", new { id = item.QueryID }, new { onclick = "return confirm('Are you sure you want to delete?')" })
</td>
</tr>
}
</table>
Edit :
@model SantechDataAccess.tbl_Query
@{
ViewBag.Title = "Customer Review : Santech Info Services";
Layout = "~/Views/Shared/_LayoutSantech.cshtml";
}
<!-- banner -->
<div class="div_bannerContent">
<p>Mail Us</p>
</div>
<!--//banner -->
<!--/w3_short-->
<div class="div_breadcrum">
<div class="div_breadcrumIn">
<ul class="short">
<li><a href="www.santechinfoservices.com">Home</a><span>|</span></li>
<li>Mail Us</li>
</ul>
</div>
</div>
<!--//w3_short-->
<!-- /features -->
<div class="banner-bottom">
<div class="container">
<div class="div_titleHead">
<h3 class="tittle">Mail <span>Us</span></h3>
<div class="row">
<div class="col-md-12">
<h3>If you have any query, Feel free to write us at <u>infoletsluk@gmail.com</u> or fill form to contact us.
</h3>
</div> <div class="row">
<div class="col-md-7 col-sm-7">
<div class="div_careerform">
@using (Html.BeginForm("Edit", "Company", FormMethod.Post))
{
@*<asp:Label ID="lbl_msg" runat="server" Text="" Visible="false"></asp:Label>*@
<div class="col-md-6 col-sm-6 paddingLeftNone10">
<div class="div_inputCareer">
@*<input id="txt_name" name ="Name" placeholder="Name" class="form-control" runat="server" />*@
@Html.EditorFor(model => model.Name)
</div>
</div>
<div class="col-md-6 col-sm-6 paddingLeftNone10">
<div class="div_inputCareer">
@*<input id="txt_email" name="Email" placeholder="Email-id" class="form-control" runat="server" />*@
@Html.EditorFor(model => model.Email)
</div>
</div>
<div class="col-md-12 col-sm-12 paddingLeftNone10">
<div class="div_inputCareer">
@*<input id="txt_phone" name="Phone" placeholder="Mobile No." class="form-control" runat="server">*@
@Html.EditorFor(model => model.Phone)
</div>
</div>
<div class="col-md-12 col-sm-12 paddingLeftNone10">
<div class="form-group">
@*<input id="txt_Query" name="Query" placeholder="Write your message here" class="form-control" runat="server" textmode="MultiLine">*@
@Html.EditorFor(model => model.Query)
</div>
</div>
<div class="col-md-12 col-sm-12 paddingLeftNone10">
<input id="btnSubmit" type="submit" class="btn btn-info" runat="server" text="Submit" />
</div>}
</div>
</div>
<div class="col-md-5 col-sm-5">
</div></div>
</div>
</div>
</div>
</div>
<!-- //features -->