.NET Core form doesn't show URL

Viewed 74

I have 2 forms placed in a row. These are the urls:

@using (Html.BeginForm("RemoveAll", "UserDocumentCategory", new { area = "Document" }))

@using (Html.BeginForm("AddAll", "UserDocumentCategory", new { area = "Document" }))

When I put a URL.Action, both urls shows up normally.

However, when placed in my Html.BeginForm, the first form disappears. I have tried to use the normal form tags but it still doesn't appear.

The only thing I can think of is to hardcode the urls but i dont want to rely on that method if possible. Here is the entire form code:

@model AppONE.Data.ViewModels.LocalUserViewModels.LocalUserViewModel
<div class="row">
    <div class="col-sm-6">
        <h4>Add All Document Categories to User</h4>
        <hr />
        @using (Html.BeginForm("AddAll", "UserDocumentCategory", new { area = "Document" }))
        {
            @Html.AntiForgeryToken()
            @Html.HiddenFor(x => x.BundleUserDetails.UserDetails.Id, new { id = "ra-id" })
            <div class="row">
                <div class="col-sm-12">
                    <div class="form-group">
                        <div class="clearfix">
                            <div class="pull-right">
                                <input type="submit" value="Add All" class="btn btn-primary" />
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        }
    </div>
    <div class="col-sm-6">
        <h4>Remove All Document Categories from User</h4>
        <hr />
        @using (Html.BeginForm("RemoveAll", "UserDocumentCategory", new { area = "Document" }))
        {
            @Html.AntiForgeryToken()
            @Html.HiddenFor(x => x.BundleUserDetails.UserDetails.Id, new { id = "ra-id" })
            <div class="row">
                <div class="col-sm-12">
                    <div class="form-group">
                        <div class="clearfix">
                            <div class="pull-right">
                                <input type="submit" value="Remove All" class="btn btn-primary" />
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        }
    </div>
</div>

Routing:

app.UseMvc(routes =>
{
    routes.MapRoute(
      name: "areas",
      template: "{area:exists}/{controller=Home}/{action=Index}/{id?}"
    );
    routes.MapRoute(
        name: "default",
        template: "{controller=Home}/{action=Index}/{id?}");

});

Controller Code:

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult RemoveAll(LocalUserViewModel Input)
{
    var res = userDocumentsCategories.RemoveAll(HttpContext, Input);
    if (res.Result == false)
    {
        TempData["Error"] = res.Message;
    }
    else
    {
        TempData["Success"] = res.Message;
    }
    return RedirectToAction("Index", "Users", new { Area = "Directory" });

}

The AddAll code is the same.

0 Answers
Related