Home C# - ASP.NET MVC - Url.Action got HTTP 404
Reply: 2

C# - ASP.NET MVC - Url.Action got HTTP 404

Zach
1#
Zach Published in 2017-11-10 06:02:02Z

Having an error of

The resource cannot be found. Description: HTTP 404.

I'm trying to do a POST method in my MVC using razor. In my controller:

ServiceListController

public ActionResult Index()
{ 
    return View();
}

[HttpPost]
private ActionResult GetData(string txtTech, string txtSerial, string txtJobNo)
{ 
    return View();
}

In my I've used the Url.Action. But when pressing the button filter, the Requested URL: /ServiceList/GetData The resource cannot be found. Do I need to add to routes or something?

<form action="@Url.Action("GetData", "ServiceList")" method="post">
    @Html.AntiForgeryToken()

    <table style="width: 400px">
            <td>
                @Html.Label("Technician", new { style = "width: 50px;" })
                <input type="text" id="txtTech" name="txtTech" class="form-control" style="width: 200px" />
            </td>
            <td>@Html.Label("a", new { style = "visibility: hidden;" })</td>
            <td>
                @Html.Label("Serial", new { style = "width: 50px;" })
                <input type="text" id="txtSerial" name="txtSerial" class="form-control" style="width: 200px" />
            </td>
            <td>@Html.Label("a", new { style = "visibility: hidden;" })</td>
            <td>
                @Html.Label("Job No", new { style = "width: 50px;" })
                <input type="text" id="txtJobNo" name="txtJobNo" class="form-control" style="width: 200px" />
            </td>
            <td>@Html.Label("a", new { style = "visibility: hidden;" })</td>
            <td>
                @Html.Label("a", new { style = "visibility: hidden;" })
                @Html.DropDownList("txtStatus", new SelectList(Enum.GetValues(typeof(wmssoft_srm.Models.Status))), "Status", new { @class = "form-control", style = "width: 200px;" })
            </td>
        </tr>
        ....
        <tr>
            <td>
                <button class="btn btn-info" type="submit" id="btFilter">Clear Filter</button>
            </td>
        </tr>
    </table>
</form>
Pankaj Toshniwal
2#
Pankaj Toshniwal Reply to 2017-11-10 06:12:28Z

try using this html.beginform like this and make post method public

 @using (Html.BeginForm("GetData", "ServiceList", FormMethod.Post))
{ @Html.AntiForgeryToken()

<table style="width: 400px">
        <td>
            @Html.Label("Technician", new { style = "width: 50px;" })
            <input type="text" id="txtTech" name="txtTech" class="form-control" style="width: 200px" />
        </td>
        <td>@Html.Label("a", new { style = "visibility: hidden;" })</td>
        <td>
            @Html.Label("Serial", new { style = "width: 50px;" })
            <input type="text" id="txtSerial" name="txtSerial" class="form-control" style="width: 200px" />
        </td>
        <td>@Html.Label("a", new { style = "visibility: hidden;" })</td>
        <td>
            @Html.Label("Job No", new { style = "width: 50px;" })
            <input type="text" id="txtJobNo" name="txtJobNo" class="form-control" style="width: 200px" />
        </td>
        <td>@Html.Label("a", new { style = "visibility: hidden;" })</td>
        <td>
            @Html.Label("a", new { style = "visibility: hidden;" })
            @Html.DropDownList("txtStatus", new SelectList(Enum.GetValues(typeof(wmssoft_srm.Models.Status))), "Status", new { @class = "form-control", style = "width: 200px;" })
        </td>
    </tr>
    ....
    <tr>
        <td>
            <button class="btn btn-info" type="submit" id="btFilter">Clear Filter</button>
        </td>
    </tr>
</table>}
Vidhyadhar Galande
3#
Vidhyadhar Galande Reply to 2017-11-10 10:42:57Z

Try This

ServiceListController

Your Method is update for

[HttpPost]
[ValidateAntiForgeryToken]
Public ActionResult GetData(string txtTech, string txtSerial, string txtJobNo)
{ 
    return View();
}

Update View Action You Can Try Two Way

1)

<form action="@Url.Action("GetData", "ServiceList")" method="post">
    @Html.AntiForgeryToken()

    <table style="width: 400px">
            <td>
                @Html.Label("Technician", new { style = "width: 50px;" })
                <input type="text" id="txtTech" name="txtTech" class="form-control" style="width: 200px" />
            </td>
            <td>@Html.Label("a", new { style = "visibility: hidden;" })</td>
            <td>
                @Html.Label("Serial", new { style = "width: 50px;" })
                <input type="text" id="txtSerial" name="txtSerial" class="form-control" style="width: 200px" />
            </td>
            <td>@Html.Label("a", new { style = "visibility: hidden;" })</td>
            <td>
                @Html.Label("Job No", new { style = "width: 50px;" })
                <input type="text" id="txtJobNo" name="txtJobNo" class="form-control" style="width: 200px" />
            </td>
            <td>@Html.Label("a", new { style = "visibility: hidden;" })</td>
            <td>
                @Html.Label("a", new { style = "visibility: hidden;" })
                @Html.DropDownList("txtStatus", new SelectList(Enum.GetValues(typeof(wmssoft_srm.Models.Status))), "Status", new { @class = "form-control", style = "width: 200px;" })
            </td>
        </tr>
        ....
        <tr>
            <td>
                <button class="btn btn-info" type="submit" id="btFilter">Clear Filter</button>
            </td>
        </tr>
    </table>
</form>

2)

@using (Html.BeginForm("GetData", "ServiceList", FormMethod.Post))
{ 
  @Html.AntiForgeryToken()

<table style="width: 400px">
        <td>
            @Html.Label("Technician", new { style = "width: 50px;" })
            <input type="text" id="txtTech" name="txtTech" class="form-control" style="width: 200px" />
        </td>
        <td>@Html.Label("a", new { style = "visibility: hidden;" })</td>
        <td>
            @Html.Label("Serial", new { style = "width: 50px;" })
            <input type="text" id="txtSerial" name="txtSerial" class="form-control" style="width: 200px" />
        </td>
        <td>@Html.Label("a", new { style = "visibility: hidden;" })</td>
        <td>
            @Html.Label("Job No", new { style = "width: 50px;" })
            <input type="text" id="txtJobNo" name="txtJobNo" class="form-control" style="width: 200px" />
        </td>
        <td>@Html.Label("a", new { style = "visibility: hidden;" })</td>
        <td>
            @Html.Label("a", new { style = "visibility: hidden;" })
            @Html.DropDownList("txtStatus", new SelectList(Enum.GetValues(typeof(wmssoft_srm.Models.Status))), "Status", new { @class = "form-control", style = "width: 200px;" })
        </td>
    </tr>
    ....
    <tr>
        <td>
            <button class="btn btn-info" type="submit" id="btFilter">Clear Filter</button>
        </td>
    </tr>
</table>}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.315568 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO