ASP.NET MVC controller not receiving the parameter from view

Ramakrishna Allada 1 Reputation point
2021-03-26T10:15:04.02+00:00

I am getting null value for the actor(which is an action parameter). I tried all possible ways to call the action method. I don't know if there is any setting in the web.config or what. When I try it in sample MVC application, it worked fine(getting parameters as expected). But the same thing is not working in my current working project. Please help me.

Html:

<table>
    <tr>
        <th>Time Info</th>
        <th>Actor</th>
        <th>Reset</th>
    </tr>
    @{
        List<LockedUser> lockedUsers = ViewBag.LockedUsers;
        foreach (LockedUser lockedUser in lockedUsers)
        {
            <tr>
                <td>@lockedUser.TimeInfo</td>
                <td>@lockedUser.Actor</td>
                <td>@Html.ActionLink("Reset", "Reset", "Admin", new { actor = "John" }, null)</td></tr>
        }
    }
</table>

Action in AdminController:

public ActionResult Reset(string actor)
        {
            if (System.Web.HttpContext.Current.Cache.Get(actor) != null)
            {
                System.Web.HttpContext.Current.Cache.Remove(actor);
                Debug.WriteLine("Reset Successfull");
                ViewBag.Message = "Reset Successfull";
            }
            else
            {
                ViewBag.Message = "Unable to reset";
            }
            return View();
        }

RouteConfig:

routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{WCP}",
                defaults: new { controller = "EmailConfirm", action = "Index", WCP = UrlParameter.Optional }
            );
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,244 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,199 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Pranam K 6 Reputation points
    2021-03-26T14:25:01.427+00:00

    Try :

    public class RecruitingController : Controller
    {
    public ActionResult ViewJobs(Guid? id)
    {
    var ListView = RecruitingLogic.GetListView(id);
    return View("ViewJobs", ListView);
    }
    }

    OR

    routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new { controller = "Home", action = "Index"}
    );

    0 comments No comments

  2. Duane Arnold 3,211 Reputation points
    2021-03-26T14:38:30.89+00:00

    @azzedinehtmlsql .ActionLink("Edit", "Edit", new { id = item.AuthorID })

    Maybe, try it without 'null' on the line.

    0 comments No comments

  3. Yihui Sun-MSFT 801 Reputation points
    2021-03-29T10:04:07.473+00:00

    Hi @Ramakrishna Allada , > But the same thing is not working in my current working project. Please help me.

    I suggest you check your current project like this:

    1. You can check whether the parameter name passed on the view is the same as the parameter name received in the action in your current project.
    2. If the parameter names are the same, as long as you assign a value to the "actor" on the view, you can get the value of the "actor" in the action.
    3. You can also try the following methods to get the value of "actor": var test=System.Web.HttpContext.Current.Request.QueryString.Get("actor");

    If the answer is helpful, please click "Accept Answer" and upvote it. Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread. Best Regards, YihuiSun

    0 comments No comments