I'm working on my first MVC5 app and am running into the following error when trying to preview a view:
"The parameters dictionary contains a null entry for parameter 'resetType' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Index(Int32)' in 'Morpheus.Controllers.ResetPasswordController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter. Parameter name: parameters"
I understand that somewhere in my view I need to pass a parameter. This is because my view is one of two that will be linked to from another view. The final URL will be: /ResetPassword?resetType=1. I don't know how to pass resetType = 1 to the controller method. I tried it in the Razor form tag and per a hidden input per this post: The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32'
Any help would be greatly appreciated. Thanks so much. Please let me know if I can post more of my code.
View Code:
@model Morpheus.Models.ResetPasswordViewModel
@{
ViewBag.Title = "Reset Password";
}
<div class="main-content mbxl">
<div class="content-frame-large-header mbl">
<h1>Enter Your Name and Email Address</h1>
@using (Html.BeginForm("Index", "ResetPassword", new {resetType = 1}, FormMethod.Post))
{
@Html.HtmlSafeValidationSummary("An Error Occurred")
<fieldset class="mbxl">
<h3>Name</h3>
<ul class="form-list">
<li class="labelset">
<span class="label-container">
<span class="label">
@Html.LabelFor(a => a.GivenName, "Given Name")
<span class="form-note">First Name</span>
</span>
</span>
<span class="field-container">
<span class="field">
@Html.TextBoxFor(a => a.GivenName, new { placeholder = "Given Name (First Name)", maxlength = "50", id = "given-name", name = "given-name", required = "required", aria_required = "true" })
</span>
</span>
</li>
<li class="labelset">
<span class="label-container">
<span class="label">
@Html.LabelFor(a => a.FamilyName, "Family Name")
<span class="form-note">Last Name</span>
</span>
</span>
<span class="field-container">
<span class="field">
@Html.TextBoxFor(a => a.FamilyName, new { placeholder = "Family Name (Last Name)", maxlength = "50", id = "last-name", name = "last-name", required = "required", aria_required = "true" })
</span>
</span>
</li>
</ul>
</fieldset>
<fieldset class="mbxl">
<h3>Email</h3>
<ul class="form-list">
<li class="labelset">
<span class="label-container">
<span class="label">
@Html.LabelFor(a => a.Email, "Email Address")
</span>
</span>
<span class="field-container">
<span class="field">
@Html.TextBoxFor(a => a.Email, new { placeholder = "Email Address", maxlength = "50", id = "email", name = "email", required = "required", aria_required = "true" })
</span>
</span>
</li>
</ul>
</fieldset>
<div class="form-submit">
<input type="hidden" name="HomePageUrl" value="@ViewData["HomePageUrl"]" />
<input type="hidden" name="ResetType" value="@ViewData["ResetType"]" />
<input type="submit" value="Submit" class="button" />
</div>
}
</div>
</div>
Controller:
public ActionResult Index(int resetType)
{
return View(new ResetPasswordViewModel() { ResetType = resetType });
}
Adding Model Code:
using System.ComponentModel.DataAnnotations;
namespace Morpheus.Models
{
public class ResetPasswordViewModel
{
public ResetPasswordViewModel()
{
}
public int ResetType { get; set; }
[Required(ErrorMessageResourceType = typeof(ControllerResources), ErrorMessageResourceName = "GivenName_Required")]
public string GivenName { get; set; }
[Required(ErrorMessageResourceType = typeof(ControllerResources), ErrorMessageResourceName = "FamilyName_Required")]
public string FamilyName { get; set; }
[Required(ErrorMessageResourceType = typeof(ControllerResources), ErrorMessageResourceName = "Email_Required")]
public string Email { get; set; }
}
}