简体   繁体   English

发布操作无效,需要帮助,将信息从视图传递到控制器

[英]Post action is not working, need help passing infromation from view into the controller

Given the following form in the Index view, which includes two hidden inputs and one input that is a slider: (The hidden imputs have their values updated by a geolocation function executed on loading the page which includes: 在“索引”视图中给出以下形式,其中包括两个隐藏的输入和一个作为滑块的输入:(隐藏的插补的值由加载页面时执行的地理位置函数更新,其中包括:

document.getElementById("startLatitude").value = lattitude; 
document.getElementById("startLongitude").value = longitude;

where the lattitude and longitude variables have been set by the geolocation call. 地理位置调用已设置的纬度和经度变量。 Also the value of the slider is updated as it is moved.) 滑块的值也随着移动而更新。)

<form name="ourform" action="Index" method="POST">
  <fieldset>
    <ul style="list-style-type:none">
      <li>
        <input type="hidden" name="startLatitude" id="startLatitude" value="" />
        <input type="hidden" name="startLongitude" id="startLongitude" value="" />10
        <input type="range" id="timeInput" min="10" max="60" value="15" step="1" onchange="showValue(this.value)" />60
      </li>
      <li>
        <br />
      </li>
      <li>
        <input type="submit" name="button" value="Let's Go!" onClick="submit" />
      </li>
    </ul>
  </fieldset>
</form>

and also an overloaded home controller method intended to receive the POST: 以及打算接收POST的重载家庭控制器方法:

[HttpPost]
public ActionResult Index(string timeInput, string startLatitude, string startLongitude)
{
  ...
}

Currently the POST action does not append the parameters to the URL when the form is submitted. 当前,提交表单时,POST操作不会将参数附加到URL。 Why not? 为什么不? What can be done to make sure they do? 可以做些什么来确保他们做到了? (What should be in the form attribute ACTION?) Alternatively, is there a better method to ensure the information is passed into the controller? (形式属性ACTION应该是什么?)或者,是否有更好的方法来确保信息传递到控制器中?

将此行修复为:

<form name="ourform" action="@Url.Action("Index")" method="POST">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM