question

RamakrishnaAllada-6984 avatar image
0 Votes"
RamakrishnaAllada-6984 asked YihuiSun-MSFT answered

ASP.NET MVC controller not receiving the parameter from view

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 }
             );


dotnet-csharpdotnet-aspnet-mvc
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

PranamK-0159 avatar image
0 Votes"
PranamK-0159 answered

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"}
);

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DuaneArnold-0443 avatar image
0 Votes"
DuaneArnold-0443 answered

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

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

YihuiSun-MSFT avatar image
0 Votes"
YihuiSun-MSFT answered

Hi @RamakrishnaAllada-6984,

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.