Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to pass a list and a string to one view from two actions of one controller? How to get this data separately in view file?
    primarykey
    data
    text
    <p><strong>Please see this code of index.cshtml below:-</strong></p> <p>List is displayed like below &amp; The string is the Caption, for which i send the company ID to Controller</p> <pre><code>@model MvcApplication3.Models.Company @foreach (var item in Model) { &lt;tr&gt; &lt;td&gt; @Html.DisplayFor(modelItem =&gt; item.CompanyName) &lt;/td&gt; &lt;td&gt; @Html.DisplayFor(modelItem =&gt; item.Template) &lt;/td&gt; &lt;td&gt; @Html.DisplayFor(modelItem =&gt; item.Caption) &lt;/td&gt; &lt;td&gt; @Html.ActionLink("Edit", "Edit", new { id = item.CompanyID }) | @Html.ActionLink("Details", "Details", new { id = item.CompanyID }) | @Html.ActionLink("Delete", "Delete", new { id = item.CompanyID }) &lt;/td&gt; &lt;/tr&gt; } &lt;/table&gt; &lt;/div&gt; @using (Html.BeginForm("GetCaption", "Company", FormMethod.Get)) { @Html.TextBox("txtCmpID") &lt;input id="btnGetCaption" type="submit" value="Get Caption" /&gt; } &lt;span style="color: Black; position: absolute; top: 100px; left: 20px;"&gt; @text = &lt;/span&gt; </code></pre> <p><strong>Code inside Controller.cs file:-</strong></p> <pre><code>private DynaPortalContext db = new DynaPortalContext(); // // GET: /Company/ public ViewResult Index() { return View(db.Companies.ToList()); } // // GET: /Company/caption [ActionName("GetCaption"),HttpPost] public ActionResult GetCaption(string txtCmpID) { Company company = db.Companies.Find(txtCmpID); return View("Index",company); } </code></pre> <p>Please tell me how to display the resulting caption from the GetCaption() method of controller into the view in @text=...</p>
    singulars
    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.
 

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