Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC3 C#4.0 / Passing variables between views
    primarykey
    data
    text
    <p>new to C# and MVC. What I would like to achieve is passing a variable as ViewData from one view to another view without using ID in the ActionResult because this view generates it own variable. I am sure there are better ways to do that, but here what I thought might work. First I made a model:</p> <pre><code>public class EventToShow { public Int64? ID { get; set; } public Int64? EventID { get; set; } } </code></pre> <p>Then I passed the variable EventID from the first View (Telerik MVC GRID) using the following:</p> <pre><code> columns.Template(item =&gt; Html.Raw(string.Format("&lt;a href=\"{0}\"&gt;{1}&lt;/a&gt;", Url.Action("tableread", "Home", new { id = (long)item.Event_ID }), "EventID"))).Width(20); </code></pre> <p>It worked using the following in my controller:</p> <pre><code> [AcceptVerbs(HttpVerbs.Post)] public ActionResult tableread1(long? id) { ViewData["EID"] = id; EventToShow ctx = new EventToShow(); ctx.ID = 1; ctx.EventID = (long)ViewData["EID"]; return RedirectToAction("EditServerSide"); } </code></pre> <p>To pass the variable to the other view I tried to use the following (I think it is very wrong):</p> <pre><code> public ActionResult EditServerSide() { EventToShow ctx = new EventToShow(); var model1 = ctx.(x =&gt; x.ID == 1); **// The error here is (Identifier** expected) ViewData["EID"] = ctx.EventID; var model = from o in new Main().OffLinePayments select new EditOffLinePayment { ID = o.ID, Amount = o.Amount, Details = o.Details }; return View(model, ViewData["EID"]) **(this must be wrong)** } </code></pre> <p>I thought maybe I should make the variable like this:</p> <pre><code>private string GetFullName() { EventToShow ctx = new EventToShow(); var name = EventToShow().Where(x =&gt; x.ID == 1); ViewData["EID"] = ctx.EventID; return name; } </code></pre> <p>First I got an error: <strong>‘GridEdit_OfflinePayment.Models.EventToShow' is a 'type' but is used like a 'variable'</strong> </p> <p>I also did not know <strong>how to incorporate returned [name] in the EditServerSide Action.</strong></p> <p>My question, is there a better way to achieve what I am trying to do, and if this approach is correct, I would appreciate any help to fix these errors</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.
 

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