今天我一直在四處尋找幾個小時,如何顯示這個我創建的字符串列表到稱爲「結果」的操作結果。我想知道是否有人知道如何在.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/)」,其中的共識是「不,他們不應該」。 –