ASP.Net Core: Pass Input Controller value into ViewComponentController Action

bigbear
 
on Jun 15, 2022 07:27 AM
684 Views

Hello everyone,

I am pretty sure if this was in a form I could simply just put 

var name = this.Request.Form["txtName"];

To get the value in the action. But since its not a form I am just trying to get this value of a hidden input in my controller so I can use it in the method.

I have tried passing in the name of the input in the action parameters using a session/TempData but that does not work because in a new tab it then uses this same value so I have to have a set value saved on the page and use that value in the controller.

I thought I could do a QueryString but also I have not had luck passing this into the action. Here is what I have.

<input id="txthguid" name="txthguid" type="hidden" value="@TempData["guid"]" />
<input asp-for="TabGuid" type="hidden" value="@TempData["guid"]" />
@await Component.InvokeAsync("DataPage", Model)

 

public async Task<IViewComponentResult> InvokeAsync(string sessionID, object txthguid, LNPartVM model)
{
    if (TempData != null)
    {
        TempData.Keep();
    }

    List<LNPartVM> lstData = null;
    try
    {
        _logger.LogInformation(txthguid.ToString());
        _logger.LogInformation(TempData["guid"].ToString());
        var jsonResponse = "";
        var tabGuid = Request.Query["txthguid"];
        _logger.LogInformation(tabGuid);
Download FREE API for Word, Excel and PDF in ASP.Net: Download
bigbear
 
on Jun 28, 2022 12:44 PM

It is not a form.

I figured out a solution. I am using TempData to store the values in hidden inputs on the screen then reading those values off with JavaScript and ajax and passing them into a controller then resetting the values to the new value passed from the controller.

I now have separate tabs working.