0

What I want to do is to sent data from a view to another (just a name)

I've tried using the ViewBag but it losts all the data in the postback. Find useful this example but: How to pass data from razor view to controller in mvc3?

The data that I'm trying to send is in the index of a list of Stores and I got a link that sends you to the View that contain the images /StoresImages.

I got in the Stores view and in StoreImages index the following inputs:

 <input type="text" name="StoreName"/>

and in StoreImagesController:

public ActionResult SaveName(string StoreName, FormCollection Collection){}

This is exactly as is in the example above but I'm getting the following error: not all code paths return a value.

What I'm missing??

Community
  • 1
  • 1
LeoJ
  • 57
  • 2
  • 6

1 Answers1

0

You should return something from ActionResult:

[HttpPost]
public ActionResult SaveName(string StoreName, FormCollection Collection)
{
    ViewBag.StoreName = StoreName;
    return View("viewName");
}

Then you can use ViewBag.StoreName in "viewName" view;

karaxuna
  • 26,752
  • 13
  • 82
  • 117
  • That is what I've been trying to do but ViewBag and TempData does not suppor postback. – LeoJ Aug 22 '12 at 22:43
  • What postback are you talking about? You should place that storename input in form and then post that form – karaxuna Aug 23 '12 at 05:58
  • did you look at the similar post I've added at top? What I'm trying to link are two views of different models. – LeoJ Aug 23 '12 at 23:23
  • did you look at the similar post I've added at top? What I'm trying to link are two views of different models. I've got a list of stores, and next to the edit delete... I've added the option images that links you to the images model (I've never do a post, is just a @html.actionlink). I can load the store name through the viewbag until I reach the edit of images. But the problem is when I hit save in the edit or create of images the viewbag empties and generates an error in the when loading the index of the images model. caused by the empty pareter index(string ConsName) when the index loads. – LeoJ Aug 23 '12 at 23:29