Reputation: 61
I am trying add Authentication where a user details will be verified by the system. However, I am having multiple errors.
Controller class, I added the following code:
public ActionResult ForgotLoginId()
{
return View();
}
[HttpPost]
public ActionResult ForgotLoginId(Testing ForgotLIDAuthentication)
{
if (ModelState.IsValid)
{
using(SUPRTestingDBEntities2 db = new SUPRTestingDBEntities2())
{
var obj = db.SUPRTesting.Where(a => a.EmailID.Equals(ForgotLIDAuthentication.EmailID) && a.TaxID.Equals(ForgotLIDAuthentication.TaxID)).FirstOrDefault();
if (obj != null)
{
Session["LoginID"] = obj.EmailID.ToString();
Session["TaxID"] = obj.TaxID.ToString();
return RedirectToAction("UserAuthentication");
}
}
}
return View(ForgotLIDAuthentication);
}
public ActionResult LIDAuthentication()
/*This is where I am getting the error CS0161 'CorporationController.LIDAuthentication()': not all code paths return a value*/
{
if (Session["LoginID"] != null)
{
return View();
}
else
{
RedirectToAction("ForgotLoginId");
}
}
View, I added the following code:
@model IEnumerable<WebApplicationTesting.Models.Testing>
@{
ViewBag.Title = "Corporation Registration";
}
@using (Html.BeginForm("LIDAuthentication", "Corporation", FormMethod.Post))
{
@Html.ValidationSummary(true)
if (ViewBag.Message != null)
{
<div style="border: 1px solid red">
@ViewBag.Message
</div>
}
<body>
<div style="height: 30px; width: 20%; font-size: large; text-align: center; margin-left: 40%; margin-right: 40%; margin-top: 5%; margin-bottom: 46px; background-color: deepskyblue; color:white" class="auto-style9">
<b>Forgot Login ID</b>
</div>
</body>
<body>
<form style="height: 475px; width: 50%; text-align: left; margin-left: 25%; margin-right: 25%; margin-top: 10%; margin-bottom: 46px; background-color: #FFFFFF; border-color:black">
<span style="margin-left:10%"></span>
<label for="Label1" style="width:20%; color:red; font-weight:normal !important">* Required Entry</label>
<br />
<br />
<br />
<span style="margin-left:10%"></span>
<label for="Label5" style="width:20%">Email Address:</label>
<label for="label6" style="color:red"><b>*</b></label>
<span style="margin-left:9%"></span>
<textarea asp-for="EmailId" style="width:50%; border-color: black" required>@Html.TextAreaFor(a => a.EmailID)</textarea>
<text>@Html.ValidationMessageFor(a => a.EmailID)</text>
In the above two line, I am having the following error: 'IEnumerable' does not contain a definition for 'EmailID' and no accessible extension method 'EmailID' accepting a first argument of type 'IEnumerable' could be found (are you missing a using directive or an assembly reference?)
<span style="margin-right:9%"></span>
<br />
<br />
<br />
<span style="margin-left:10%"></span>
<label for="Label1" style="width:17%">Tax ID:</label>
<select id="taxid" style="width:10%">
<option value="fein">FEIN</option>
<option value="ssn">SSN</option>
</select>
<label for="label2" style="color:red"><b>*</b></label>
<span style="margin-left:20%"></span>
<textarea asp-for="TaxID" style="width:30%; border-color: black" required placeholder="xxxxxxxxx" maxlength="9">@Html.TextAreaFor(a => a.Password)</textarea>
<text>@Html.ValidationMessageFor(a => a.Password)</text>
In the above 2 line, I am having the following error:The type arguments for method 'TextAreaExtensions.TextAreaFor(HtmlHelper, Expression>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
<span style="margin-right:9%"></span>
<br />
<br />
<br />
<span style="margin-right:9%"></span>
<label for="label6" style="color:darkblue; font-weight:normal !important">(Enter Federal Tax ID) or (SSN) 9 numbers, do not enter dashes or spaces.</label>
<br />
<br />
<span style="margin-right:9%"></span>
<label for="label6" style="color:darkblue; font-weight:normal !important">If you don't know Email Address, then please call Helpdesk at 1-800-000-0000</label>
<br />
<br />
<span style="margin-left:20%"></span>
<button type="submit" onclick="" style="width: 20%; color: white; background-color: deepskyblue; border-color:black"><b>Submit</b></button>
<span style="margin-left:20%"></span>
<button type="reset" style="width:20%; background-color:deepskyblue; color:white; border-color:black"><b>Clear</b></button>
<br />
<br />
<br />
<span style="margin-left:10%"></span>
<label for="label6" style="color:red; font-weight:normal !important; visibility: hidden">Email Address or the Login ID does not match. Please verify and enter the details again.</label>
</form>
</body>
}
Global.asax has:
namespace WebApplicationTesting
{
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configure(WebApiConfig.Register);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"LoginPage", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "CorporationController", action = "LoginPage", id = "" } // Parameter defaults
);
}
}
}
The Model class is as follows:
public partial class Testing
{
public int LoginID { get; set; }
[Required]
public string EmailID { get; set; }
[Required]
public int TaxID { get; set; }
public string Password { get; set; }
[Required]
public string CorporationName { get; set; }
}
Can someone help me with this. The page is
Upvotes: 0
Views: 545
Reputation: 4068
the method LIDAuthentication doesn't return a value the session value is null.
public ActionResult LIDAuthentication()
{
if (Session["LoginID"] != null)
{
return View();
}
return new RedirectToActionResult("action", "controller", null);
}
The page model is an IEnumerable containing Testing object, instead of one Testing object. It looks for a property on the IEnumerable that's not there
Change
@model IEnumerable<WebApplicationTesting.Models.Testing>
to
@model WebApplicationTesting.Models.Testing
also check the code that call's the view so the model is correct
Upvotes: 3