How can I do (Write Html Code with Controller ?)

Harun Ergün 260 Reputation points
2023-05-18T13:35:16.61+00:00

I don't know how to write to SQL. Normally I can add name or id into class in View and write it to SQL on Controller side. But now I have 2 dropdownlists and I don't know how to write it to SQL

My question is How can write html code ıd and name for going to İnsert SQL ? (I know picture 1 for text but I dont know @Html.RenderAction

Please Help me !!

5

User's image

4

User's image

3

User's image

2 (I know UserName and UserSurName how can add with html )

User's image

1

User's image

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,404 questions
{count} votes

Accepted answer
  1. Lan Huang-MSFT 28,826 Reputation points Microsoft Vendor
    2023-05-19T07:33:38.8233333+00:00

    Hi @Harun Ergün,

    I know picture 1 for text but I dont know @Html.RenderAction

    You need to get the dropdown name like "input":

    model.City = form["DrpSehir"].Trim();
    model.City1 = form["Drpilce"].Trim();
    

    User's image

    (I know UserName and UserSurName how can add with html )

    If I understand correctly, you want to persist the value on the page when the create button is clicked, you can return the model.

     return View(model);
    

    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


2 additional answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 60,871 Reputation points
    2023-05-18T15:42:56.9566667+00:00

    a <select> just posts its name and selected value just like a text box. If you are trying to get both the value and text, you have two options:

    1. on postback regenerate the city list, and lookup the text by the passed value (best method)
    2. with javascript copy the text to a hidden field when a value is selected.
    0 comments No comments

  2. Leenaa Khan 0 Reputation points
    2023-08-05T09:07:37.1833333+00:00

    In order to perform an INSERT SQL operation using the values from the two dropdown lists in your HTML code, you'll need to utilize JavaScript or jQuery to capture the selected values from the dropdowns. Then, you can send an AJAX request to the controller with the selected values, where you'll handle the database insertion logic.

    0 comments No comments