Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • ThomasBrunbjerg 90 posts 182 karma points
    Sep 08, 2017 @ 06:42
    ThomasBrunbjerg
    0

    Get values from model in select element to assign to Request.Form[]

    I need to store both the name and the id of the option the user chooses in my SQL Database. Right now I am only storing the Id, by setting the value of the option to the current Id of the iteration.

    @foreach (var item in selection)
    {
         if (item.Id.ToString() == contentId)
         {
             //dont mind this, just for displaying purposes         
         }
         else
         {
            <option value="@item.Id" @(Request.Form["førstePrio"] != null && Request.Form["førstePrio"].ToString().Equals(item.Name.ToString()) ? " selected" : "")>@item.Name</option>
         }
     }
    

    I don't have a surface controller associated with the view, since I am doing my SQL connection and commands in the view.

    How can I store the @item.Name value as well in a separate Request.Form to be saved in the database?

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies