user3261018
user3261018

Reputation: 43

Can anybody explain why these two ActionResults return different results despite being the same?

I'm making a portfolio. In my Portfolio view, I have the following code:

<a href="@Url.Action("Index", "Project", new { _title = @ViewBag.ProjectContainer.Projects[x].Title, _imagePath = @ViewBag.ProjectContainer.Projects[x].ImagePath, _brief = @ViewBag.ProjectContainer.Projects[x].Brief, _description = @ViewBag.ProjectContainer.Projects[x].FullDescription, })" class=" readmore-button button">Learn More</a>

It's placed within a loop that goes through the ViewBag and draws a button for each "Project" in the "Project Container". When clicked, this should lead to the project page and display the relevant information.

When written as above (calling the Index() method in the Project controller) everything works as intended and the page displays thusly:

http://gyazo.com/57901eab7ccf8be45270312a92880072

However, when I call another method in my controller, which I have named "SetProject", the following happens:

http://gyazo.com/6a5c6164dc4e8b55ec8a6684ce469652

My controller methods look like the following:

public ActionResult Index(string _title, string _imagePath, string _brief, string _description)
{
    ProjectViewModel proj = new ProjectViewModel { Title = _title, ImagePath = _imagePath, Brief = _brief, FullDescription = _description };
    return View("Project", proj);
}

public ActionResult SetProject(string _title, string _imagePath, string _brief, string _description)
{
    ProjectViewModel proj = new ProjectViewModel { Title = _title, ImagePath = _imagePath, Brief = _brief, FullDescription = _description };
    return View("Project", proj);
}

You might noticed that these are identical - hence my question, WHY do they look so different? Why does the second simply not work?

I'm quite new to ASP.NET and the Razor view engine and trying to learn, but got very stuck here. Would appreciate any and all help.

Could this be something to do with the Route config? The only difference I can see is the URL being different for the broken one (having the extra "/SetProject")

Upvotes: 1

Views: 157

Answers (1)

Selman Gen&#231;
Selman Gen&#231;

Reputation: 101681

Why does the second simply not work?

Because of your css references.It is working actualy just it doesn't look like what you expected. Make sure you include your all css references inside of Layout and make sure your Project View using your Layout page.

Upvotes: 1

Related Questions