locked
how to send values in my page to controller with @Html.ActionLink RRS feed

  • Question

  • User1928394251 posted

    i have view that section1 fill with my table (afishstudio=name,family,date,time),section 2 i fill(modiran-name,modiran_semat)(table=modiran)***********************************************************.                                                                                                                                                               i want to send all of values in my page to new table , new view (controller) with :

    <div class="panel-body">

    ********@Html.ActionLink(" ثبت آفیش ", "index4", "formafish", routeValues: new

    name = ViewBag.name,
    family = ViewBag.family,
    Date = ViewBag.date,
    time=ViewBag.time,
    modiran_name = <input name="modiran_name" />,
    modiran_semat = <input name="modiran_semat" />
    },
    htmlAttributes:{ (

    }, new { @class = "btn btn-success" })
    </div>*

    thats right?

    help me please

    Sunday, December 30, 2018 5:39 AM

All replies

  • User1724605321 posted

    Hi aabedeni056,

    You can refer to below code sample which makes your code readable :

    @Html.ActionLink(
        linkText: " ثبت آفیش ",
        actionName: "index4",
        controllerName: "formafish",
        routeValues: new
        {
            name = ViewBag.name,
            family = ViewBag.family,
            Date = ViewBag.date,
            time = ViewBag.time,
            modiran_name = "somevalue",
            modiran_semat = "somevalue1"
        },
        htmlAttributes: new { @class = "btn btn-success" }
    )
    

    Best Regards,

    Nan Yu

    Monday, December 31, 2018 2:44 AM
  • User1928394251 posted

    thanks.but any value pass to controller.i dont know... please help me....

    Monday, December 31, 2018 6:11 AM
  • User1930269528 posted

    You can create a form and post to it and read in the action method:

    @using(Html.BeginForm("index4", "formafish",FormMethod.Post))
    {
    
     Html.TextBox("name",ViewBag.name)
     Html.TextBox("family ",ViewBag.family)
     Html.TextBox("Date",ViewBag.date)
     Html.TextBox("time",ViewBag.time)
     Html.TextBox("family ",ViewBag.family)
     Html.TextBox("modiran_name")
     Html.TextBox("modiran_semat",ViewBag.family)
    
    
     <button type="submit" value="save" class = "btn btn-success"/>
    }

    and in action method you can read them like:

    [HttpPost]
    public ActionResult Index4(FormCollection form)
    {
       var name = form["name"].ToString();
       var family = form["family"].ToString();
       ......
       ......
    }

    A more better approach would be to create a model and bind your view with model and use strongly typed helper methods to post data as model object instead of playing around with magic string keys in the form collection.

    Monday, December 31, 2018 7:26 AM