0

i want send 3 parameters from a view page to an action that need 3 incoming argument like this:

  public ActionResult Get_full(int providers_id, int providers_change_request, 
  string persian_name)
    {......}

and the view page is like this:

   @foreach (var item in Model)
        {
            <tbody>
            <tr>
                <td id="insert_log">@item.insert_log</td>
                <td id="persian_name">@item.persian_name</td>
                <td 
     id="providers_change_request_id">@item.providers_change_request_id
                </td>
                <td id="providers_id">@item.providers_id</td>
                <td>

                    <a href="/Default/Get_full">
                          clickme
                    </a>
                </td>
            </tr>
            </tbody>
        }

please help me how can i do this

tereško
  • 58,060
  • 25
  • 98
  • 150
Zohreh Zamani
  • 41
  • 1
  • 7
  • 4
    Possible duplicate of [ASP.NET MVC - passing parameters to the controller](https://stackoverflow.com/questions/155864/asp-net-mvc-passing-parameters-to-the-controller) – Brank Victoria Oct 22 '18 at 10:53

4 Answers4

0

Many a ways to do this. 1) Assign name to these elements of HTML suppose @item.providers_id and in your action give the same name like below. As many as you want to receive

public ActionResult Get_full(int id) 2) Second method is you can receive in action through Request.form['id'](name of tag or element) 3) Third way to doing this is Request['id'](name of tag inside) 4) Fourth way for make class object of all attribute you want to receive in action and receive action argument.

if you want to send Action to action data put it in ViewBag then receive it in another view or pass it as argument while redirecting to action

0

Optionally, you can use TempData as well. It uses Session["AnyKey"] variable to store your data and you can access from action-to-action or controller-to-controller.

Please refer, https://www.codeproject.com/Articles/786603/Using-TempData-in-ASP-NET-MVC

Ashokan Sivapragasam
  • 2,033
  • 2
  • 18
  • 39
0

You should use @Url.Action

in your case, you can call like this. (I believe your controller name is "Default")

<a href="@Url.Action("Get_full","Default", new { providers_id= yourId, providers_change_request= yourRequest, persian_name = yourString})">
    clickme
</a>

Please mind these information:

  • Get_full is your method name in your controller
  • Default is your controller
  • You have to match param names on Url.Action. Otherwise your method can not get the information that you provide.
Mehmet Taha Meral
  • 3,315
  • 28
  • 30
0

While I accept & learn from the accepted answer, we can also wrap those fields inside the html form. BeginForm() in Html helpers can post the form values when submitting the form.

@using (Html.BeginForm("Get_Full", "Default")) 
{
    @Html.AntiForgeryToken()

    <div class="form-horizontal">
        <h4>Topic</h4>
        <hr />
        <div class="form-group">
            @Html.LabelFor(model => model.insert_log, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.DisplayFor(model => model.insert_log, new { htmlAttributes = new { @class = "form-control" } })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.persian_name, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.DisplayFor(model => model.persian_name, new { htmlAttributes = new { @class = "form-control" } })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.providers_change_request_id, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.DisplayFor(model => model.providers_change_request_id, new { htmlAttributes = new { @class = "form-control" } })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.providers_id, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                <div class="checkbox">
                    @Html.DisplayFor(model => model.providers_id)
                </div>
            </div>
        </div>

        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="GetFullInfo" class="btn btn-default" />
            </div>
        </div>
    </div>
}
Ashokan Sivapragasam
  • 2,033
  • 2
  • 18
  • 39