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 8777049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:12:00+00:00 2026-06-13T19:12:00+00:00

The scenario is, I have a form to sign in user, which will invoke

  • 0

The scenario is, I have a form to sign in user, which will invoke an action method. The action method will return true/false depending on valid/invalid username. If it returns false, I want a jquery method to show a message. I can pass the value as a model view, but problem is when the page is first time requested, that value is null because action method for post is not invoked that time, therefore its showing an error like object reference is null. How to handle this kind of situation. I’m not giving the code, coz coding is not my problem, I need to know the best practice to handle this. Thanks.

OK, Here is the Jquery method I tried.

<script type="text/javascript">

        $(document).ready(function () {
            (' #SignIn').click(function () {
                if (@Model.test === null) //Error is showing here, on the @Model.test call
                {
                $(' #Message').text("Null")
                }
                if(@Model.test===false)
                 {
                    $(' #Message').text("Invalid");
                }
            });
        });
    </script>
  • 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-13T19:12:01+00:00Added an answer on June 13, 2026 at 7:12 pm

    if your are returning your result from action in model then you need to perform java-script operation after the POST call.
    Try this.

    //In your Controller 
    
    [HttpGet]
    public ActionResult SomeAction()
    {
        var model = new ModelView();
        model.test = false;
        return (model)
    }   
    
    [HttpPost]
    public ActionResult SomeAction(ModelView model)
    {
        if(ModelState.IsValid)
        {
            // write your logic here for validating user 
             model.test = true;
             return View(model);
        }
        model.test = false;
        return (model)
    }  
    
    // In View 
    
    @model ViewModel 
    
    @if (model.test == true)
    {
        <script type="text/javascript">
            $(document).ready(function () {
                $(' #Message').text("Null")
    
            });
    
        </script>
    }
    else
    {
     <script type="text/javascript">
        $(document).ready(function () {
             $(' #Message').text("Invalid");
    
        });
    
    </script>
     }
    

    i have give you solution according to your situation but i would suggest you submit form using Ajax.BeginForm or javascript and return JSON from action.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Scenario I have got this form: <form action=EditShippingInfo.asp method=POST id=frmShippingInfo> <!-- stuff --> <input
Scenario: I have multiple text boxes in which a user will enter data into
Scenario I have an InfoPath form. the user fills it in the details, and
the scenario is i have a form in my Yii project that will take
Simple scenario: I have a signup form, with user name, password, email address, may
Hello I have a form which have subj_ids. So here's the scenario. I have
Scenario: I have a WPF desktop application which will be distributed on different machines
I have a single form that, depending on which radio button is clicked (Login
I have this basic Drupal scenario and question: I have a form which accepts
Scenario I have a Windows Forms Application. Inside the main form there is a

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.