Avatar of sai krishnan
sai krishnan
Flag for India asked on

textbox and dropdown is not accepting the value in mvc

hi experts,
There is a text box for accepting phoneno and gender using dropdown. when i full the form with phone number and gender it is not accepting the entered value in textbox or dropdown for inserting.can anyone help me on this

in sql,it is inserting as 0 and dropdown as null

this is in cshtml
 <tr>
                <td>
                    @Html.LabelFor(a=>a.Phoneno)
                </td>
            </tr>

            <tr>
                <td>
                    @Html.TextBoxFor(a => a.Phoneno)
                    @Html.ValidationMessageFor(a => a.Phoneno)






                </td>

            </tr>
            <tr>
                <td>
                    @Html.Label("Gender")
                </td>
            </tr>

            <tr>
                <td>
                    @Html.DropDownListFor(a => a.gender, new List<SelectListItem>{

                    new SelectListItem {Text="Male",Value="0" },
                                        new SelectListItem {Text="Female",Value="1" }
              })
                    @Html.ValidationMessageFor(a => a.gender)


                </td>

in entity framework

 public int Phoneno { get; set; }
        public string gender { get; set; }


in controller
  mydbs itr = new mydbs();
            string result = itr.insertcmd(reg);
.NET MVCMicrosoft SQL ServerC#

Avatar of undefined
Last Comment
sai krishnan

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Prakash Samariya

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
sai krishnan

ASKER
thank you
if I add model.isvalid ,it always return false.
Prakash Samariya

If not, please provide more relevant part code to check with (hard to understand from current block).
sai krishnan

ASKER
hi sir,


i have form with field first name,last name,email,phone and gender etc
Here phone is a text box which accept integer value.my problem is in this text box. It is not accepting the given phone number value instead it is inserting only null value.but other values are varchar value,it got inserted. i am using sql 2016 database

this is the cshtml of phoneno


 <tr>
                <td>
                    @Html.LabelFor(a=>a.Phoneno)
                </td>
            </tr>
            <tr>
                <td>
                    @Html.TextBoxFor(a=>a.Phoneno)

                </td>

            </tr>

i have created separate class library project.this class library project as edmx .model value of phoneno is coming from this edmx.
model cs of edmx

public int Phoneno { get; set; }

controller cs for passing values

 mydbs itr = new mydbs(); -this is class library project
                string result = itr.insertcmd(reg); -this is the method in that class file
                ViewData["result"] = result;


code in class library


 public string insertcmd(registration reg)
        {
           using (customerEntities con = new customerEntities())
            {

                string result = con.registrations.Add(reg).ToString();
                con.SaveChanges();
                return result;




            }

        }

    }
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
SOLUTION
Prakash Samariya

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
sai krishnan

ASKER
thank you .i will try and let you know sir

thank you once again