Reputation:
In my ASP.NET Application, there is an If Condition on Details.cshtml
page, which looks for the state, if it's Requested
, it will enable the Button, and by manually clicking the Button, ProcessRequest()
function will be triggered.
I want to make this Process automatically, e.g. if the Condition is Requested, triggered the ProcessRequest
without clicking the Button, manually.
Details.cshtml
@if (Model.State == CredentialState.Requested)
{
<tr>
<td>
<a role="button" asp-controller="Credentials" asp-action="ProcessRequest" asp-route-id="@Model.CredentialRecordId">Send credential</a>
</td>
</tr>
}
CredentialsController.cs
[HttpGet]
public async Task<IActionResult> ProcessRequest(string id)
{
// Code
}
Upvotes: 1
Views: 794
Reputation: 2498
It's called "Redirect", do it from Controller/Action "Details".
[HttpGet]
public async Task<IActionResult> Details(string id) // from action "Details"
{
// code to get Model first
...
// check Model.State
if (Model.State == CredentialState.Requested)
{
//return await ProcessRequest(Model.CredentialRecordId); //as madreflection suggested
return RedirectToAction("ProcessRequest", "Credentials", new { id = Model.CredentialRecordId}); //redirect with your own function.
}
return View(Model);
}
Upvotes: 1