首先如果你给出例子,你能在aspx引擎中做到吗?我对此最为熟悉。如果没有,我想没关系,我会尝试找出剃须刀引擎的例子。
这是我上一个问题与我取得的进展的升级。
我正在尝试创建一个接收用户 ID 的搜索框,然后显示与用户输入关联的类,然后将其显示在表格中。如果没有,则搜索按钮下方的消息应显示未找到类别。这就是我到目前为止所拥有的。我的示例中有很多红色下划线。我不知道我在哪里搞砸了。
html
<div align="center">
<form id="searchUser" method="post" action="what do I put here?">
<table align="center">
<tr>
<td class="label">
Enter ID:
</td>
<td>
<input type="text" name="UserId" id="UserId" value="<%(string)(ViewBag.userid)%>" />
</td>
</tr>
<tr>
<td>
<button class="searchButton" id="searchButton">Search</button>
</td>
</tr>
</table>
</form>
</div>
<hr />
<%if(ViewBag.searchClass !=null)
{ %>
<h2>Search Resuls</h2>
<br />
<%AAlexUsers.Models.SearchClass searchClassList= ViewBag.searchClass;%>
<table>
<tr>
<th>
UserID:
</th>
<th>
Email:
</th>
<th>
Last Four Digits:
</th>
</tr>
<tr>
<td class="content">
<%=searchClassList.userId%>
</td>
<td class="content">
<%=searchClassList.email%>
</td>
<td class="content">
<%=searchClassList.lastFourdigits%>
</td>
</tr>
<%} %>
</table>
<% else %>
<% { %>
<h2>No Class found.</h2>
<% } %>
控制器 这是我为搜索按钮创建类的实例的地方
public ActionResult Search()
{
string userId = Request["UserId"];
bool view = false;
if (Request["UserId"] == null)
{
view = true;
}
if (!view)
{
AAlexUsers.Models.SearchClass searchClass = new Models.SearchClass();
{
searchClass.lastFourdigits = "2222";
searchClass.userId = "12345";
searchClass.email = "diaz@gmail.com";
string lastFourdigits = searchClass.lastFourdigits;
string userIdd = searchClass.userId;
string email = searchClass.email;
ViewBag.searchClass = searchClass;
ViewBag.lastFourdigits = lastFourdigits;
ViewBag.userId = userIdd;
ViewBag.email = email;
}
}
return View();
模型
namespace AAlexUsers.Models
{
public class SearchClass
{
public string userId { get; set; }
public string email { get; set; }
public string lastFourdigits { get; set; }
public SearchClass()
{
userId = "";
email = "";
lastFourdigits = "";
}
}
}