2021-01-30

Is any other way of Accessing HTML:Textboxfor inside view in action Controller?

I read JSON from URL and display as table format in MVC View DotnetCore.I have @Html.TextBoxFor control inside this same view under form control.

To display in table format, i have used both register @model and using statement inside view.So i can't able to access @Html.TextBoxFor values in controller action method.Is any way of accessing HTML:Textboxfor inside view in action Controller?

@model System.Data.DataTable 
@using System.Data;

@using (Html.BeginForm("Index", "Admin", FormMethod.Post)){ @Html.TextBoxFor(s => s.ImportJsonUrlName, new { id = "PickUrlID", style = "width:800px" })


<table class="table table-bordered table-dark">
    <thead>
        <tr>
            @foreach (DataColumn col in Model.Columns)
            {
                <th>@col.ColumnName</th>
            }
        </tr>
    </thead>
    <tbody>
        @foreach (DataRow row in Model.Rows)
        {
            <tr>
                @foreach (DataColumn col in Model.Columns)
                {
                    <td>@row[col.ColumnName]</td>
                }
            </tr>
        }
    </tbody>
</table>

Controller code:

 [HttpPost]
    public IActionResult Index(AdminModel model)
    {
        DataTable dt = new DataTable();
        string json = (new WebClient()).DownloadString("https://raw.githubusercontent.com/wedeploy-examples/supermarket-web-example/master/products.json");
        dt = JsonConvert.DeserializeObject<DataTable>(json);
        return View(dt);
    }


from Recent Questions - Stack Overflow https://ift.tt/3pyP9gX
https://ift.tt/eA8V8J

No comments:

Post a Comment