Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You are mixing a lot of concepts here.</p> <ol> <li>Go to Visual Studio and create a new MVC website.</li> <li>Run it and see how it works.</li> <li>Then go on google and lookup the concept of interfaces.</li> <li>Go back to your newly created MVC website and see the difference to what you have postet here.</li> </ol> <p>Edit: What you are trying is not possible! You are asking the MVC framework to create an instance of an interface, this is not possible!</p> <p>What you must do is to have a concrete class in the Action parameter:</p> <pre><code>[HttpGet] public ActionResult AddVechicle() { return View(new Vehicle()); } [HttpPost, ValidateInput(false)] public JsonResult AddVechicle(Vehicle newVehicle) { // I expect that newVechicle is populated via the form } </code></pre> <p>you could then declare the "Vehicle" class as follows</p> <pre><code>public class Vehicle :IVehicle { String vehicleName { get; set; } int maxSpeed { get; set; } } </code></pre> <p>I havent testet if the view will accept an interface as a model, you might better change it into the class "Vehicle"</p> <pre><code>&lt;% // view name: AddVehicle // This is not working, I am not sure how to tell the view I want the form // to use the interface located in the following namespace. @Model Vehicle; using (Html.BeginForm("AddVehicle", "NewVechicle", FormMethod.Post)) // Below I understand that I would need some code in the form of Html.EditorFor to // populate the Vehicle concrete class in the form. &lt;%: Html.EditorFor(model =&gt; model.VehicleName) %&gt; &lt;%: Html.EditorFor(model =&gt; model.maxSpeed) %&gt; &lt;%: } %&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload