Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET MVC Standard Link/Href As Save Button And Model IS NUll
    primarykey
    data
    text
    <p>Okay so, i am totally new to MVC and I'm trying to wrap my head around a few of the concepts. I've created a small application...</p> <p>This application has a view for creating a new Individual record. The view is bound to a model <strong>ViewPage</strong>... And I have a associated <strong>IndividualController</strong> which has a <strong>New</strong> method...</p> <p>The <strong>New</strong> method of the IndividualController looks like this...</p> <pre><code>public ActionResult New() { var i = new Individual(); this.Title = "Create new individual..."; i.Id = Guid.NewGuid(); this.ViewData.Model = new Individual(); return View(); } </code></pre> <p>Now, the above all seems to be working. When the view loads I am able to retrieve the data from the Individual object. The issue comes into play when I try and save the data back through the controller...</p> <p>In my <strong>IndividualController</strong> I also have a <strong>Save</strong> method which accepts an incoming parameter of type <strong>Individual</strong>. The method looks like...</p> <pre><code> public ActionResult Save(IndividualService.Individual Individual) { return RedirectToAction("New"); } </code></pre> <p>Now, on my view I wanted to use a standard html link/href to be used as the "Save" button so I defined an ActionLink like so...</p> <pre><code> &lt;%=Html.ActionLink("Save", "Save") %&gt; </code></pre> <p>Also, defined in my view I have created a single textbox to hold the first name as a test like so...</p> <pre><code> &lt;% using (Html.BeginForm()) { %&gt; &lt;%=Html.TextBox("FirstName", ViewData.Model.FirstName)%&gt; &lt;% } %&gt; </code></pre> <p>So, if I put a break point in the <strong>Save</strong> method and click the "Save" link in my view the break point is hit within my controller. The issue is that the input parameter of the Save method is null; even if I type a value into the first name textbox...</p> <p>Obviously I am doing something completely wrong. Can someone set me straight...</p> <p>Thanks in advance...</p>
    singulars
    1. This table or related slice is empty.
    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