I
I
Igor Braduloff2021-03-05 09:10:59
ASP.NET
Igor Braduloff, 2021-03-05 09:10:59

How to pass data from View to Controller?

Good afternoon! There is a view Index.cshtml, when clicking, you need to pass the list to the method in the UsersController.cs controller

@model IEnumerable<Certificates_MVC_EF_2021.Models.User>

@{Html.BeginForm("CreateDocument", "Home", FormMethod.Get);
{
<div>
    <input type="submit" value="Create Document" style="width:150px;height:27px" />
</div>
}
Html.EndForm();
}


and a method in the CreateDocument controller, where I want to transfer the list from the view
public FileResult CreateDocument()
        {
            //Creates an instance of WordDocument class 
            WordDocument document = new WordDocument();
           ..............................................................................
            //Download Word document in the browser
            return File(stream, "application/msword", "Table.docx");
        }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
BasiC2k, 2021-03-05
@BasiC2k

Should I pass a list from model or some other list?
You have page content hidden under html helpers. What's inside is anyone's guess.

P
Peter, 2021-03-05
@petermzg

There is a backend which is the code that runs on the server and a front that is displayed to the client.
The controller is back.
A click is an operation in the View, which is located on the client's computer in the browser.
The interaction between these parts goes through the Internet. And here HTTP or WebSocket requests are available to you.
Here through requests and transfer the data.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question