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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:08:14+00:00 2026-05-28T01:08:14+00:00

I have simple form. It contains few texboxes and one dropdown list. And I

  • 0

I have simple form. It contains few texboxes and one dropdown list. And I cant get selected item id to save it into database.

This is controller method whitch displaing a form

public ActionResult DisplayForm()
        {
            ViewBag.State = new SelectList(conn.state, "STATE_Id", "STATE_Name");
            return View(new order_data());
        }

this is method whitch should save data into database

 [HttpPost]
        public ActionResult MakeOrder(order_data data, state stateId)
        {
            if (ModelState.IsValid)
            {
                conn.order_data.Add(data);
                conn.SaveChanges();
                RedirectToAction("Index", "Home");
            }
            return View();
        }

This is my view

@model bookstore.order_data

@{
    ViewBag.Title = "Dane osobowe";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>DisplayForm</h2>

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

@using (Html.BeginForm("MakeOrder","Order"))
{
    @Html.ValidationSummary(true)
    <fieldset>

     <div class="editor-label">
            @Html.LabelFor(model => model.ORDA_Name)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.ORDA_Name)
            @Html.ValidationMessageFor(model => model.ORDA_Name)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.ORDA_LastName)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.ORDA_LastName)
            @Html.ValidationMessageFor(model => model.ORDA_LastName)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.ORDA_Email)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.ORDA_Email)
            @Html.ValidationMessageFor(model => model.ORDA_Email)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.ORDA_Phone)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.ORDA_Phone)
            @Html.ValidationMessageFor(model => model.ORDA_Phone)
        </div>


        <div class="editor-label">
            @Html.LabelFor(model => model.ORDA_CityName)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.ORDA_CityName)
            @Html.ValidationMessageFor(model => model.ORDA_CityName)
        </div>


        <div class="editor-label">
            @Html.LabelFor(model => model.state)
        </div>
        @Html.DropDownList("State", "--wybierz województwo--")



        <div class="editor-label">
            @Html.LabelFor(model => model.ORDA_StreetName)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.ORDA_StreetName)
            @Html.ValidationMessageFor(model => model.ORDA_StreetName)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.ORDA_StreetNr)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.ORDA_StreetNr)
            @Html.ValidationMessageFor(model => model.ORDA_StreetNr)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.ORDA_HomeNr)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.ORDA_HomeNr)
            @Html.ValidationMessageFor(model => model.ORDA_HomeNr)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.ORDA_ZIP)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.ORDA_ZIP)
            @Html.ValidationMessageFor(model => model.ORDA_ZIP)
        </div>
        <p>
            <input type="submit" value="Create" />
        </p>
    </fieldset>
}

and this is model whitch contains client data

namespace bookstore
{
    public partial class order_data
    {
        public order_data()
        {
            this.orders = new HashSet<orders>();
        }
        [Key]
        public int ORDA_ID { get; set; }
        [ForeignKey("state")]
        public Nullable<int> State_STATE_Id { get; set; }
        [Required]
        [DisplayName("Miasto")]

        public string ORDA_CityName { get; set; }
        [Required]
        [DisplayName("Ulica")]
        public string ORDA_StreetName { get; set; }
        [Required]
        [DisplayName("Numer ulicy")]
        public string ORDA_StreetNr { get; set; }
        [Required]
        [DisplayName("Numer domu")]
        public string ORDA_HomeNr { get; set; }
        [Required]
        [DisplayName("Kod pocztowy")]
        public string ORDA_ZIP { get; set; }
        [Required]
        [DisplayName("Email")]
        public string ORDA_Email { get; set; }
        [Required]
        [DisplayName("Imię")]
        public string ORDA_Name { get; set; }
        [Required]
        [DisplayName("Nazwisko")]
        public string ORDA_LastName { get; set; }
        [Required]
        [DisplayName("Telefon")]
        public string ORDA_Phone { get; set; }
        [Required]
        [DisplayName("Województwo")]
        public virtual state state { get; set; }
        public virtual ICollection<orders> orders { get; set; }
    }

}

and this is model which contains dropdown list data

public partial class state
    {
        public state()
        {
            this.order_data = new HashSet<order_data>();
        }

        public int STATE_Id { get; set; }
        public string STATE_Name { get; set; }

        public virtual ICollection<order_data> order_data { get; set; }
    }

By the way, i need to pass a orderid into controller too and i dont know how, becouse id always equals 0

Please, help

  • 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-05-28T01:08:15+00:00Added an answer on May 28, 2026 at 1:08 am

    Isn’t orderId (ORDA_ID) a KEY in your order_data table ? So it’s being assigned when you insert a row into the table. So either I don’t fully understand your question or you’re not trying to pas orderId into the controller.

    after you execute

    conn.order_data.Add(data);
    conn.SaveChanges();
    

    you will be able to get your ORDA_ID by :

    int orderId = data.ORDA_ID;
    

    if this is what you need

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

Sidebar

Related Questions

Using Rails 3.0.7. I have a simple form which shows all records from one
I have a very simple voting form. It contains a single text field for
I have a simple ExtJs form panel which contains a fileuploadfield. When I submit
I have one simple User Registration form. It includes name, age, sex & city.
I have a form that contains one date element and 3 time elements. This
I have a simple form that contains a lot of duplicate textboxes. I have
I have a simple web form which has a couple list boxes and a
I have simple form. <form target=_blank action=somescript.php method=Post id=simpleForm> <input type=hidden name=url value=http://...> <input
Have a simple form (only extract fields here) but for some reason the JQserilization
I have a simple form on a view page, implemented as a user control,

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.