-1

I am rendering a new view from some view(say mainView) by using Html.ActionLink("","",new{id=packageID})
and my controller action(ActionLink passing control to) look like
public ActionResult editChecks(int packageID) {return View();}
Now at Rendered View("editChecks") i want to hide packageID so that i can use it(by passing it to another controller action) on another action by any means

i.e I am using form inside View("editChecks") which is submitting data to some action say(action2)


Presently I am using this in my view("editChecks")
and string pid = Request.Form["packageID"]; at my controller action(need packageID) is this works fine for long run??? Or is there any alternate i should go for???

Tim Post
  • 33,371
  • 15
  • 110
  • 174
RollerCosta
  • 5,020
  • 9
  • 53
  • 71

1 Answers1

3

You can declare any expected parameters in the method. You can also declare a default if it is not supplied String packageID = "0"

EDIT: your question is confusing. If you want to access it on the view, use viewbag.

public ActionResult action2(Int32 packageID) {

  // can use packageID here

 // Or make it accessable on the view
 ViewBag.PackageID = packageID;
  return View();
}

On the view you can access this by typing

@ViewBag.PackageID

Though I question why your packageID is a String in some cases. Should you not be using Int32?

EDIT: Going on your comments,

@Html.Hidden("PackageID", (Int32)@ViewBag.PackageID)

Will have the attribute on the page, hidden. And will be passed to any called submit (assuming within the form) as the name "PackageID"

IAmGroot
  • 13,760
  • 18
  • 84
  • 154
  • I don't want to Display value passed by controller action to view rather i need that value at the same view in hidden format(so that value is hidden to the end user). And i am passing value to view by using ViewData dictionary(@ViewBag.PackageID) – RollerCosta Dec 26 '11 at 05:50
  • Like @Html.HiddenFor(model=>model.PackageID) is used for – RollerCosta Dec 26 '11 at 05:52
  • Then just do `@Html.Hidden("PackageID", @ViewBag.PackageID)` This is the same as above, but without being attached to a model. i.e. you can assign it anything. – IAmGroot Jan 03 '12 at 11:36
  • 4
    That does not work for me, I'm not sure how that is valid ...@Html.Hidden("PackageID", @ViewBag.PackageID) you should have to cast it like this @Html.Hidden("PackageID", (object)ViewBag.PackageID) – Tom Stickel Jun 19 '12 at 08:49
  • Why did you accept this answer? Does it work? Because it doesn't work for me –  Apr 01 '14 at 14:24