0

Is there an easy way to pass an object from my controller to view to controller?

I tried ViewData["compaignId"] but that didn't work.

Controller "Content" :

ViewData["CompaignId"] = id;

View "Content" :

<div>
    @Html.ActionLink("Go To Team Creation", "Team", ViewData["CompaignId"])
</div>

Controller "Team":

public ActionResult Team(long CompaignId)
{
    ....
}

Thanks,

3 Answers 3

1

In general you should use a ViewModel for things like that. But you can use the ViewBag too.

ViewBag.CompaignId = id;
Sign up to request clarification or add additional context in comments.

Comments

0

U can use:

Controller "Content" :

ViewBag.CompaignId = id;

View "Content" :

<div>
    @Html.ActionLink("Go To Team Creation", "Team", new 
    { 
        CompaignId = (long)ViewBag.CompaignId 
    })
</div>

Controller "Team":

public ActionResult Team(long CompaignId)
{
    ....
}

1 Comment

I would like to send tweet using LinqToTwitter, have you any example or documentation Thanks,
0

You should take a look at this overload

public static MvcHtmlString ActionLink(
    this HtmlHelper htmlHelper,
    string linkText,
    string actionName,
    Object routeValues
)

And you can pass anonymous object as last parameter

<div>
    @Html.ActionLink("Go To Team Creation", "Team", new { campaignId = (int)ViewData["CompaignId"] })
</div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.