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

Harun Ergün 260 Reputation points

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 !!


User's image


User's image


User's image

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

User's image


User's image

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

    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 ( 60,871 Reputation points

    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

    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