Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8621697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:52:37+00:00 2026-06-12T06:52:37+00:00

Aspx Engine When I enter an invalid User Id in the text box and

  • 0

Aspx Engine

When I enter an invalid User Id in the text box and hit search, “No Class found” is suppose to be displayed. Now “Search Result” is displayed. It seems not to be hitting the else statement.

html

<div align="center">
    <form id="searchUser" method="post" action="Search">
        <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 style ="display:none;">
        <td class="label">
            Email:
        </td>
        <td>
            <input type="text" name="Email" id="Text1" value="<%=(string)(ViewBag.email)%>" />
        </td>
    </tr>
      <tr style ="display:none;">
        <td class="label">
            lastFourDigits:
        </td>
        <td>
            <input type="text" name="LastFourDigits" id="Text2" value="<%=(string)(ViewBag.lastFourDigits)%>" />
        </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 />
    <%List<AAlexUsers.Models.SearchClass> searchClassList= ViewBag.searchClass;%>
    <%if(searchClassList.Count>0)
    <table>
          <%foreach (AAlexUsers.Models.SearchClass searchClass in searchClassList)
     {%>
      <tr>
         <td>
            UserID:
        </td>
        <td class="content">
          <%=searchClass.userId%>
        </td>
    </tr>
    <tr>
        <td>
            Email:
        </td>
        <td class="content">
         <%=searchClass.email%>
        </td>
    </tr>
    <tr>
        <td>
        Last Four Digits:
        </td>
        <td class="content">
          <%=searchClass.lastFourdigits%>
         </td>
    </tr>
    <%} %>
    <%} %>
 </table>

    <%} else %>
 <%{ %>
    <h2>No Class found.</h2>
 <%} %>

Controller

public ActionResult Search()
{
    string userId = Request["UserId"];
    string email = Request["Email"] ?? string.Empty;
    string lastFourdigits = Request["LastFourDigits"] ?? string.Empty;

    bool view = false;

    if (string.IsNullOrEmpty(userId))
    {
        view = true;
    }
    if (!view)
    {
        List<AAlexUsers.Models.SearchClass> searchClass = 
            AAlexUsers.Models.SearchClass.Users(userId,email,lastFourdigits);
        {
            ViewBag.searchClass = searchClass;
            ViewBag.lastFourdigits = lastFourdigits;
            ViewBag.userId = userId;
            ViewBag.email = email;
        }
    }
    return View();
}

Model

public class SearchClass
{
    public string userId { get; set; }
    public string email { get; set; }
    public string lastFourdigits { get; set; }

    public static List<AAlexUsers.Models.SearchClass> 
        Users(string userId, string email, string lastFourdigits)   
    {
        SearchClass Alex = new SearchClass();
        Alex.userId = "1234";
        Alex.email = "Alex@gmail.com";
        Alex.lastFourdigits = "1885";

        SearchClass Emilio = new SearchClass();
        Emilio.userId = "0928";
        Emilio.email = "Cubano@gmail.com";
        Emilio.lastFourdigits = "0706";

        SearchClass Ulysses = new SearchClass();
        Ulysses.userId = "0914";
        Ulysses.email = "lysses@gmail.com";
        Ulysses.lastFourdigits = "01zx";

        var list = new List<SearchClass>();
        list.Add(Alex);
        list.Add(Emilio);
        list.Add(Ulysses);


        IEnumerable<SearchClass> result = list;
        if (!string.Empty.Equals(userId))
            result = result.Where(u => u.userId == userId);

        return result.ToList();
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T06:52:39+00:00Added an answer on June 12, 2026 at 6:52 am

    First of all, in your controller you are creating a searchClass:

    List<AAlexUsers.Models.SearchClass> searchClass = AAlexUsers.Models.SearchClass.Users(userId,email,lastFourdigits);   
    

    In your Users(…) method you the following line always returns a List that is not null.

    result = result.Where(u => u.userId == userId);
    
    return result.ToList();
    

    In the case that result is null, result.ToList() will return a List with 0 items in it.
    Once you’ve received your List, you are then assigning it on this line in your controller:

    ViewBag.searchClass = searchClass;
    

    Once in your view, you are checking for:

    <% if (ViewBag.searchClass !=null)
    

    which will always be true since you return an empty List.

    If you want to see if the proper result was returned, based on your posted code, you should not rely only on if the list is null. Instead you should do this:

    <% if (ViewBag.searchClass !=null && ViewBag.searchClass.Count > 0)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

ASPX Engine I have a webform with a search button. A user enters the
I created a custom Razor View engine Right now when I do: public class
I'm using the spark view engine with my asp.net mvc application. In my aspx
aspx file: <asp:Repeater ID=Repeater_sorular runat=server> <HeaderTemplate> </HeaderTemplate> <ItemTemplate> <div class=div_soru> <div class=div_soru_wrapper> <%#Eval(Subject)%> <asp:RadioButtonList
aspx script: <script type=text/javascript> $(document).ready(function() { $(.div_soru).hide(); $(.div_soru).first().show(); $(.onceki).click(function() { if ($(this).closest(.div_soru).prev(.div_soru).html() != null)
I am creating an ASPX application that collects data from the user can creates
I am using MSSQL and C# to write a search engine. I got a
The web application that I am developing right now has something called quiz engine
We have a flash gateway page displayed to users (only once) before they enter
Good day, everyone. I found strange behavior within ASP.NET engine when it handles non-existent

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.