Avatar of sai krishnan
sai krishnanFlag 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
ASKER CERTIFIED SOLUTION
Avatar of Prakash Samariya
Prakash Samariya
Flag of India image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of sai krishnan
sai krishnan
Flag of India image

ASKER

thank you
if I add model.isvalid ,it always return false.
If not, please provide more relevant part code to check with (hard to understand from current block).
Avatar of sai krishnan
sai krishnan
Flag of India image

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;




            }

        }

    }
SOLUTION
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of sai krishnan
sai krishnan
Flag of India image

ASKER

thank you .i will try and let you know sir

thank you once again
Microsoft SQL Server
Microsoft SQL Server

Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.

171K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo