0

I am attempting to pass data from a view to a controller in my .net application. I want to do this while keeping as much of the original html syntax as possible since it and the corresponding css were imported form adobe muse. I created the following model i am attempting to fill:

public class LoginModel
{
    public string Email { get; set;}
    public string Password { get; set; }
}

I am attempting to retrieve the input in the following method:

[HttpPost]
public IActionResult LoginBody(LoginModel info)
{
    System.Diagnostics.Debug.WriteLine(email);
    System.Diagnostics.Debug.WriteLine(password);

    return View();
}

My html is:

<form class="form-grp clearfix grpelem" id="widgetu732" method="post" enctype="multipart/form-data" action="">
    <div class="clearfix grpelem" id="u733-4">
    </div>
    <div class="clearfix grpelem" id="u734-4">
    </div>
    <div class="clearfix grpelem" id="u743-4">
    </div>
    <button class="submit-btn NoWrap clearfix grpelem" id="u744-3" type="submit" value="&nbsp;" tabindex="3">
        <div style="margin-top:-13px;height:13px;">
            <p>&nbsp;</p>
        </div>
     </button>
     <div class="fld-grp clearfix grpelem" id="widgetu749" data-required="true">
          <label class="fld-label actAsDiv clearfix grpelem" id="u752-4" for="widgetu749_input"><!-- content --><span class="actAsPara">PASSWORD:</span></label>
          <span class="fld-input NoWrap actAsDiv clearfix grpelem" id="u750-4" placeholder="PASSWORD"><!-- content --><input class="wrapped-input" type="text" id="widgetu749_input" name="Password" tabindex="2" /></span>
      </div>
      <div class="fld-grp clearfix grpelem" id="widgetu735" data-required="true">
          <label class="fld-label actAsDiv clearfix grpelem" id="u738-4" for="widgetu735_input"><!-- content --><span class="actAsPara">EMAIL:</span></label>
          <span class="fld-input NoWrap actAsDiv clearfix grpelem" id="u737-4" placeholder="EMAIL"><!-- content --><input class="wrapped-input" type="text" id="widgetu735_input" name="Email" tabindex="1" /></span>
    </div>
</form>

How should I modify my html to be able to receive the input?

DMop
  • 463
  • 8
  • 23

2 Answers2

0

You can use

[HttpPost]
public IActionResult LoginBody()
{
    string email = Request["custom_U735"];
    string password = Request["custom_U749"];

return View();
}
Dylan
  • 323
  • 2
  • 5
  • 17
0

You need to change name of your input fields

<div class="fld-grp clearfix grpelem" id="widgetu749" data-required="true">
      <label class="fld-label actAsDiv clearfix grpelem" id="u752-4" for="widgetu749_input"><!-- content --><span class="actAsPara">PASSWORD:</span></label>
      <span class="fld-input NoWrap actAsDiv clearfix grpelem" id="u750-4" placeholder="PASSWORD"><!-- content --><input class="wrapped-input" type="text" id="widgetu749_input" name="Password" tabindex="2" /></span>
  </div>
  <div class="fld-grp clearfix grpelem" id="widgetu735" data-required="true">
      <label class="fld-label actAsDiv clearfix grpelem" id="u738-4" for="widgetu735_input"><!-- content --><span class="actAsPara">EMAIL:</span></label>
      <span class="fld-input NoWrap actAsDiv clearfix grpelem" id="u737-4" placeholder="EMAIL"><!-- content --><input class="wrapped-input" type="text" id="widgetu735_input" name="Email" tabindex="1" /></span>
</div>

Console.Write will not work in ASP.NET as it is called using the browser. You can use Debug.Writeline

See Stack Overflow question Where does Console.WriteLine go in ASP.NET?

Furthermore inorder to access form data

[HttpPost]
public IActionResult LoginBody(LoginModel info)
{
    Debug.WriteLine(info.Email);
    Debug.WriteLine(info.Password);

    return View();
}

Note: Debug.WriteLine only works during debugging.

Aakash
  • 155
  • 1
  • 3
  • 11
  • I changed my write statements as well as the names of my input fields and it doesn't seem to quite be working. Would you mind taking another look? I edited my code above – DMop Dec 20 '17 at 18:48