0

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:

public class EventToShow
    {
        public Int64? ID { get; set; }

        public Int64? EventID { get; set; }
    }

Then I passed the variable EventID from the first View (Telerik MVC GRID) using the following:

 columns.Template(item => Html.Raw(string.Format("<a href=\"{0}\">{1}</a>", Url.Action("tableread", "Home", new { id = (long)item.Event_ID }), "EventID"))).Width(20);

It worked using the following in my controller:

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

To pass the variable to the other view I tried to use the following (I think it is very wrong):

     public ActionResult EditServerSide()
        {

             EventToShow ctx = new EventToShow();
            var model1 = ctx.(x => 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)**
        }

I thought maybe I should make the variable like this:

private string GetFullName()
        {
            EventToShow ctx = new EventToShow();
            var name = EventToShow().Where(x => x.ID == 1);
            ViewData["EID"] = ctx.EventID;
            return name;
        }

First I got an error: ‘GridEdit_OfflinePayment.Models.EventToShow' is a 'type' but is used like a 'variable'

I also did not know how to incorporate returned [name] in the EditServerSide Action.

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

hncl
  • 2,295
  • 7
  • 63
  • 129
  • I checked this link and found the answer http://msdn.microsoft.com/en-us/library/dd394711.aspx. – hncl Sep 25 '11 at 05:06
  • Best to post your link as a answer and mark it as one. This way people will see the question has already been answered and nobody needs to looks at it ;) – Kevin Cloet Sep 25 '11 at 22:03
  • The solution did not work as I hoped, the variable did not pass to a third action. – hncl Sep 25 '11 at 22:09

1 Answers1

0

From what I understand of the question is that you would like to pass data between several Actions? Like some sort of wizard steps process where you can pass data between multiple Actions?

If that's the case then here are some related questions and their answers:

How do I pass data across ActionResults in MVC 3?

multi-step registration process issues in asp.net mvc (splitted viewmodels, single model)

Community
  • 1
  • 1
Kevin Cloet
  • 2,956
  • 1
  • 19
  • 36