Note that there are some explanatory texts on larger screens.

plurals
  1. POValue not being passed properly to controller from view
    primarykey
    data
    text
    <p>I have an MVC application that when a link is clicked a page needs to be displayed based on the same values on another page. I can't figure out why what's getting passed is null instead of the string. My code is below.</p> <p>Controller:</p> <pre><code>public string searchQ { get { return (string)Session["searchQ"]; } set { Session["searchQ"] = value; } } public ActionResult Index() { Session["InitialLoad"] = "Yes"; return View(); } [HttpPost] public ActionResult Index(string heatSearch) { ViewBag.SearchKey = heatSearch; searchQ = heatSearch; return View(); } public ActionResult Index_Perm() { ViewBag.SearchKey = searchQ; return View(); } public ActionResult PartialMainLim(string heatSearch) { HomeModel C = new HomeModel(); ChemViewModel D = new ChemViewModel(); D = C.QueryResults(heatSearch); return PartialView(D); } public ActionResult PartialMain(string heatSearch) { HomeModel C = new HomeModel(); ChemViewModel D = new ChemViewModel(); D = C.QueryResults(heatSearch); return PartialView(D); } </code></pre> <p>The code in the index view looks like this (this one works):</p> <pre><code>@if (ViewBag.SearchKey != null) { &lt;div&gt; @Html.Action("PartialMainLim", "Home", (string)ViewBag.SearchKey) &lt;/div&gt; } </code></pre> <p>And in the index_perm view:</p> <pre><code>@if(ViewBag.SearchKey != null) { &lt;div&gt; @Html.Action("PartialMain", "Home", (string)ViewBag.SearchKey) &lt;/div&gt; } </code></pre> <p>When I check the value of SearchKey in both views it is correct. However for the method "PartialMain" null gets passed instead of the string, despite SearchKey being correct. This all works for the other view though. What am I doing wrong?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload