Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC & Url.Action

Hi I am having difficulties using Url.Action method, please see my code below, what am I doing wrong....? (I'm using MVC Razor)

<a href='<%: @Url.Action("Edit", "Student", 
    new { id = item.DealPostID }) %>'>Hello          </a>

Student is my StudentController and Edit is ActionResult method.

like image 379
Benk Avatar asked Nov 11 '11 22:11

Benk


People also ask

What is MVC?

MVC (Model-View-Controller) is a pattern in software design commonly used to implement user interfaces, data, and controlling logic. It emphasizes a separation between the software's business logic and display.

What is MVC and how it works?

The Model-View-Controller (MVC) framework is an architectural/design pattern that separates an application into three main logical components Model, View, and Controller. Each architectural component is built to handle specific development aspects of an application.

Why MVC is used for?

MVC is primarily used to separate an application into three main components: Model, View, and Controller. This level is considered the lowest level when compared with the View and Controller. It primarily represents the data to the user and defines the storage of all the application's data objects.

Is MVC an OOP?

MVC is a software design pattern built around the interconnection of three main component types: Model, View, and Controller, often with a strong focus on Object-Oriented Programming (OOP) software paradigms. MVC is a framework for building web applications using an MVC Design.


2 Answers

Try this:

@Html.ActionLink("Hello", "Edit", "Student", new { id = item.DealPostID }, null)
  • Argument 1: Link text
  • Argument 2: Action name
  • Argument 3: Controller name
  • Argument 4: Route values
  • Argument 5: HtmlAttributes. This is set to null so that it doesn't append "?Length=" to your URL.

That should work out for you.

like image 165
James McConnell Avatar answered Sep 27 '22 19:09

James McConnell


Remove <%: %> from your Razor view. Those are WebForms tags.

<a href='@Url.Action("Edit", "Student", 
    new { id = item.DealPostID })'>Hello          </a>
like image 25
Jakub Konecki Avatar answered Sep 27 '22 19:09

Jakub Konecki