if else condition is not working

Analyst_SQL 3,551 Reputation points
2023-03-22T00:21:12.6166667+00:00

below ,if else condition is not working


 <div>
                    @Html.LabelFor(model => model.PID, "Pack_ID", htmlAttributes: new { @class = "control-label col-md-4" })

                    @Html.EditorFor(model => model.PID, new { htmlAttributes = new { @class = "form-control col-md-10", @id = "Pack_ID" } })
                    @Html.ValidationMessageFor(model => model.PID, "", new { @class = "text-danger" })
                </div>


                var packID = $('#Pack_ID').html();
                
                    alert('same order');
                }
                else {
                    alert('not same');
                }
                if (packID == "" && packID=="1")
                {
                    addrow(prdno);
               
                }
               
                else {
                    alert('Bale Already Packed');
                        
                }

if i am applying one condition for example packID=="" then it is working fine,but if i am using both packID =="" && PackID=="1" ,then it does not work and give message bale already packed

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,451 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,819 questions
0 comments No comments
{count} votes

Accepted answer
  1. Lan Huang-MSFT 29,166 Reputation points Microsoft Vendor
    2023-03-22T05:34:40.1833333+00:00

    Hi @Analyst_SQL ,

    packID == "" and packID="1" cannot be implemented at the same time.

    You should change && (and) to || (or).

      if (packID == "" || packID=="1")
    

    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.