We help IT Professionals succeed at work.

textbox and dropdown is not  accepting the value in mvc

147 Views
Last Modified: 2017-12-02
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);
Comment
Watch Question

IT Professional
CERTIFIED EXPERT
Top Expert 2015
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
sai krishnanSoftware Developer

Author

Commented:
thank you
if I add model.isvalid ,it always return false.
Prakash SamariyaIT Professional
CERTIFIED EXPERT
Top Expert 2015

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

Author

Commented:
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;




            }

        }

    }
Prakash SamariyaIT Professional
CERTIFIED EXPERT
Top Expert 2015
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
sai krishnanSoftware Developer

Author

Commented:
thank you .i will try and let you know sir

thank you once again