2012-09-24 30 views
-1

首先,如果您给出示例,您是否可以在aspx引擎中执行此操作。我对此非常熟悉。如果没有,我想这没关系,我会尝试将剃须刀发动机的例子弄清楚。按用户ID搜索类,然后在表中显示类

这是从我最后一个问题的升级中取得的进展。

我想创建一个搜索框,需要在用户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 = "[email protected]"; 

       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 = ""; 
     } 
    } 
} 
+1

action =“我在这里放什么?”应该是行动=“搜索” – prashanth

+0

我的if语句在它下面有一条红线。你知道为什么会发生这种情况。你能检查我的语法吗? – Yusuf

+1

什么是确切的异常/错误? – prashanth

回答

1

我在VS2010(MVC3)中运行代码时遇到了一个错误。

</table>前应<%} %>

你可以找到很多关于剃刀良好的信息相比,网络表单引擎here