user1088259
user1088259

Reputation: 355

How send params from tag helper?

I want pass params from view to controller, but dont know how make it with asp.net tag-helpers. What i make wrong? Params not received on controller.

<form asp-controller="Role" asp-action="Create" asp-route-returnurl="@ViewBag.ReturnUrl" method="post" class="form-horizontal" role="form">
    <div class="form-group">
        <label asp-for="@Model.Name" class="col-md-2 control-label"></label>
        <div class="col-md-10">
            <input asp-for="@Model.Name" class="form-control" />

        </div>
    </div>
  <div class="form-group">
        <div class="col-md-offset-2 col-md-10">
            <input type="submit" value="Create" class="btn btn-default" />
        </div>
    </div>
</form>

How pass data from inputbox to controller?

[HttpPost]
        public ActionResult Create(string rolename)
        {
            try
            {
                this.context.Roles.Add(new IdentityRole()
                {
                    Name = rolename
                });
                this.context.SaveChanges();

            }

Upvotes: 0

Views: 477

Answers (1)

regnauld
regnauld

Reputation: 4336

In your action method change rolename to name. The default model binder doesn't know where to initialize this rolename from. Additionally you can inspect what is posted on the server via fiddler.

Upvotes: 2

Related Questions