提交表单时如何从 mgt-people-picker 获取输入值 [英] How to get input values from mgt-people-picker when a FORM is submitted
问题描述
我在 ASP.Net Razor 应用程序中使用 mgt-people-picker
,使用 ProxyController
从 Graph API 获取所有数据.一切正常.
I'm using mgt-people-picker
from within an ASP.Net Razor application, using a ProxyController
to get all the data from the Graph API.
Everything is working fine.
现在我想从我创建的包含人员列表的表单中获取信息,来自 mgt-people-picker
元素:
Now I want to get the infos from a Form I've created, containing a people list, from the mgt-people-picker
element :
从我的 ASP.NET 后端,一旦提交表单;我拥有输入中的所有信息,除了 mgt-people-picker
元素.
From my ASP.NET backend, once the form is submitted; I have all the info from my inputs, except the mgt-people-picker
element.
有谁知道一个简单的解决方案来从输入文本中获取人员列表,在 POST 操作期间发出?
Anyone knows a simple solution to get the list of people form the input text, issued during the POST action ?
或者我们应该使用javascript技巧吗?
Or should we use a javascript trick ?
推荐答案
好的,如果有人遇到同样的问题,这里是经过大量调查后的解决方案.
Ok, if anyone has the same issue, here is the solution, after a LOT of investigations.
您必须使用
的 模板 和 data-type=selected-person
.在这个模板部分,你需要添加
You have to use the template of <mgt-people-picker>
with data-type=selected-person
.
In this template section, you need to add
- 具有正确属性的
(我在源代码中找到的) - 一个
来存储值:
- An
<mgt-person>
with the correct properties (That I've found in the source code) - An
<input type=hidden />
to store the values:
<mgt-people-picker>
<template data-type="selected-person">
<input type="hidden" value="{{person.userPrincipalName}}" name="people" id="people" />
<mgt-person view="oneLine" person-details="{{person}}" fetchImage=true></mgt-person>
</template>
</mgt-people-picker>
在您的后端处理程序中,您将获得在 Request.Form["people"]
属性中选择的所有人员
From within your backend handler, you will get all the persons selected in the Request.Form["people"]
property
public void OnPost()
{
foreach (var personSelected in Request.Form["people"])
Debug.WriteLine(personSelected);
}
该解决方案优雅且易于使用&理解.不幸的是,文档缺乏自定义的详细信息,尤其是模板 :)
The solution is elegant and easy to use & understand. Unfortunatelly, the documentation lacks details on the customization, especially on templates :)
这篇关于提交表单时如何从 mgt-people-picker 获取输入值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!