今天我一直在四处寻找几个小时,如何显示这个我创建的字符串列表到称为“结果”的操作结果。我想知道是否有人知道如何在.aspx页面上显示它?显示搜索结果
public class Testimonials
{
public string AddTestimonials { get; set; }
public string SearchTestimonials { get; set; }
public List<string> results = new List<string>();
public void getSearchResults(string keyword)
{
string query = "SELECT content from Testimonial where Content like '%@p1%';"; //insert statement
SqlConnection db = new SqlConnection(@"");
SqlCommand command = new SqlCommand(query, db);
command.Parameters.AddWithValue("@p1", keyword); // seting @p1 to the content
db.Open();
SqlDataReader reader = command.ExecuteReader();
DataTable results = new DataTable();
results.Load(reader); //Loads remaining surgeon credentials into a data table.
foreach (DataRow row in results.Rows)
{
string cont = row["content"].ToString();
this.results.Add(cont);
}
db.Close();
}
}
public ActionResult Testimonials()
{
return View();
}
[HttpPost]
[Authorize]
public ActionResult Testimonials(Testimonials model, string returnUrl)
{
if (model.AddTestimonials != null)
{
string query = "Insert Testimonial (content,date,surgeonID) VALUES (@p1,CURRENT_TIMESTAMP,@p2);"; //insert statement
SqlConnection db = new SqlConnection(@"");
SqlCommand command = new SqlCommand(query, db);
command.Parameters.AddWithValue("@p1", model.AddTestimonials); // seting @p1 to the content
command.Parameters.AddWithValue("@p2", Convert.ToString(Session["surgeonID"]));
db.Open();
command.ExecuteNonQuery();
db.Close();
return RedirectToAction("Testimonials");
}
if (model.SearchTestimonials != null)
{
model.getSearchResults(model.SearchTestimonials);
return RedirectToAction("Testimonials");
}
return View();
}
我试过“对于每个变种”在很多不同的变化没有成功。这是迄今为止的aspx:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared /Site.Master"Inherits="System.Web.Mvc.ViewPage<TEAM3OIE2S.Models.Testimonials >"%>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Testimonials
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<form id="form1" runat="server">
<h2>Testimonials</h2>
<% using (Html.BeginForm()) { %>
<%: Html.TextBoxFor(m => m.AddTestimonials)%>
<input type="submit" value="Add" />
<% } %>
<% using (Html.BeginForm()) { %>
<%: Html.TextBoxFor(m => m.SearchTestimonials)%>
<input type="submit" value="Search" />
<% } %>
</form>
</asp:Content>
我编辑了自己的冠军。请参阅:“[应该在其标题中包含”标签“](http://meta.stackexchange.com/questions/19190/)”,其中的共识是“不,他们不应该”。 –