不知道Request对象的来源

时间:2023-02-07 04:02:27

So there is this method in my controller

所以在我的控制器中有这种方法

[HttpPost]
public ActionResult Summary(string id, Summary model)
{
  int projectID;
  if (Int32.TryParse(id, out projectID))
  {
   switch (Request["PageType"])
   {
      case "Results":
       model = new Summary(SummaryType.SCS, GetSCSData(projectID, Request["Names"], true), projectID, SCSView.ResultsPage);
       break;
      case "Recipients":
       model = new Summary(SummaryType.SCS, GetProjectData(projectID, Request["Names"]), projectID)
       {
          Names = Request["Names"],
          HTMLAttachment = ParseBool(Request["HTMLAttachment"])
        };
        break;                    
       default:
        model = new Summary();
         break;
        }
    }

And was wondering where the Request["Names"] came from. I understand that is the request object from my Http request call. But how was it constructed and sent? I know it has something to do with my view, which look like this

并且想知道Request [“Names”]的来源。我理解这是来自我的Http请求调用的请求对象。但它是如何构建和发送的?我知道它与我的观点有关,看起来像这样

 using (Html.BeginForm(Summary, "Mycontroller", FormMethod.Post, new { id = "gridForm" }))
  { 
    @(Html.Kendo().Grid(Model.scsGridList) ... kendo stuff
    <input id="gridPage" name="PageType" type="hidden" value="" />
    <input id="gridProjectID" name="ProjectID" type="hidden" value="@Model.ProjectID" />
    <input id="gridJobs" name="Jobs" type="hidden" value="" />
    <input id="gridHTMLAttach" name="HTMLAttachment" type="hidden" value="true" />
  <div style="width: 100%; padding-top:5px;">                           
    <a id="email" href="#"><span class="ui-icon ui-icon-mail-closed linkicon"></span>Email</a>                            
  </div>

In my javascript is this

在我的JavaScript中是这样的

$("#email").on("click", function (e) {
        SendTo("Recipients");
    });

function SendTo(pageType){
    var values = GetSelectedValues();
    if(values){
        $("#gridPage").val(pageType);
        $("#gridJobs").val(values);
        $("#gridForm").submit();
    } else {
        $("#gridMessage").html("Please select a job.");
    }
}

I am just confuse as to how the Request object came to be populated with data such as Request["HTMLAttachment"] and Request["Names"]. Does it know to map to the model? Am I making sense?

我只是混淆了Request对象如何填充Request [“HTMLAttachment”]和Request [“Names”]等数据。是否知道要映射到模型?我有道理吗?

1 个解决方案

#1


0  

Because you placed all your inputs inside form, then when you submit it browser will populate key-value pairs, where keys are the names of inpurs inside form. It will do for every input element in form, even invisible. And as it stated here: http://msdn.microsoft.com/en-us/library/ms524948(v=vs.90).aspx

因为您将所有输入放在表单中,所以当您提交它时,浏览器将填充键值对,其中键是表单内的inpurs的名称。它将对表单中的每个输入元素执行操作,甚至是不可见的。正如它在此处所述:http://msdn.microsoft.com/en-us/library/ms524948(v = vs。90).aspx

The Request object retrieves the values that the client browser passed to the server during an HTTP request.

Request对象检索客户端浏览器在HTTP请求期间传递给服务器的值。

This is provided to you by asp.net for free. asp.net mvc uses it. http://stephenwalther.com/archive/2008/03/18/asp-net-mvc-in-depth-the-life-of-an-asp-net-mvc-request

这是由asp.net免费提供给您的。 asp.net mvc使用它。 http://stephenwalther.com/archive/2008/03/18/asp-net-mvc-in-depth-the-life-of-an-asp-net-mvc-request

#1


0  

Because you placed all your inputs inside form, then when you submit it browser will populate key-value pairs, where keys are the names of inpurs inside form. It will do for every input element in form, even invisible. And as it stated here: http://msdn.microsoft.com/en-us/library/ms524948(v=vs.90).aspx

因为您将所有输入放在表单中,所以当您提交它时,浏览器将填充键值对,其中键是表单内的inpurs的名称。它将对表单中的每个输入元素执行操作,甚至是不可见的。正如它在此处所述:http://msdn.microsoft.com/en-us/library/ms524948(v = vs。90).aspx

The Request object retrieves the values that the client browser passed to the server during an HTTP request.

Request对象检索客户端浏览器在HTTP请求期间传递给服务器的值。

This is provided to you by asp.net for free. asp.net mvc uses it. http://stephenwalther.com/archive/2008/03/18/asp-net-mvc-in-depth-the-life-of-an-asp-net-mvc-request

这是由asp.net免费提供给您的。 asp.net mvc使用它。 http://stephenwalther.com/archive/2008/03/18/asp-net-mvc-in-depth-the-life-of-an-asp-net-mvc-request