C# 在常规模型视图中渲染内容

C# 在常规模型视图中渲染内容,c#,asp.net-mvc,twilio,C#,Asp.net Mvc,Twilio,我正在学习twilio教程,他们有一个文件hello-monkey.cshtml的内容,如下所示: @{ // make a list of senders we know, indexed by phone number ****var people = new Dictionary<string, string>() { {"+14158675309","Curious George"}, {"+14158675310","Boo

我正在学习twilio教程,他们有一个文件hello-monkey.cshtml的内容,如下所示:

@{
    // make a list of senders we know, indexed by phone number
    ****var people = new Dictionary<string, string>() { 
        {"+14158675309","Curious George"},
        {"+14158675310","Boots"},
        {"+14158675311","Virgil"},
        {"+14158675312","Marcel"}
    };

    // if the caller is known, then greet them by name
    // otherwise, consider them just another monkey
    string name = "Monkey";
    if (!string.IsNullOrEmpty(Request["From"]))
    {
        name = people[Request["From"]];
    }**

    // now greet the caller
    Response.ContentType = "text/xml";**
}
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Say>Hello @name.</Say>
</Response>
@{
//列出我们知道的发件人,按电话号码索引
****var people=新字典(){
{“+14158675309”,“好奇的乔治”},
{14158675310,“靴子”},
{“+14158675311”,“维吉尔”},
{“+14158675312”,“马赛尔”}
};
//如果对方是熟人,那么就直呼其名
否则,认为他们只是另一只猴子
string name=“Monkey”;
如果(!string.IsNullOrEmpty(请求[“来自”]))
{
姓名=人[请求[“来自”];
}**
//现在问候打电话的人
Response.ContentType=“text/xml”**
}
你好@name。
他们希望我们将页面呈现为

如何在服务器端编写此代码。。在模型部分,这样我就可以调用页面


换句话说,是否可以在模型零件中传输粗体部分代码?

此处为Twilio evangelist

我不太清楚你所说的“模型部分”是什么意思,但是如果你不想把它放在视图中,你可以直接在控制器中执行上面显示的所有操作:

public class PhoneController : TwilioController  
   public ActionResult Hello() {

      var response = new TwilioResponse();
      response.Say(name);

      return TwiML(response);    
   }
}
我建议将Twilio.Mvc助手库安装到ASp.NETMVC项目中,以获得TwilioController基类。这使您可以使用上面显示的TwiML助手方法将TwiML命令作为ActionResult返回


希望能有所帮助。

谢谢Devin。。我今天很傻,我注意到了上面的代码。我会在家里试试。非常感谢您的快速回答。我将搜索internet以查看其他twiml命令,如Say、Dial等。谢谢twiml元素的所有内容都记录在这里: