我需要在每个产品的视图中显示动态生成的div。
这就是为什么我在View层上编写以下功能的原因:
if (!HttpListener.IsSupported)
{
Console.WriteLine("Server does not support Http Listener.");
return;
}
// URI prefixes required,
if (prefixes == null || prefixes.Length == 0)
throw new ArgumentException("prefixes required");
// Create a listener.
HttpListener listener = new HttpListener();
// Add the prefixes.
foreach (string s in prefixes)
{
listener.Prefixes.Add(s);
}
listener.Start();
listener.AuthenticationSchemes = AuthenticationSchemes.Basic;
Console.WriteLine("About to listen to " + prefixes[0].ToString());
if (listener.IsListening) {
Console.WriteLine("Currently Listening to " + prefixes[0].ToString());
}
//Wait until a connection is made before continuing
//allDone.WaitOne();
// Note: The GetContext method blocks while waiting for a request.
HttpListenerContext context = listener.GetContext();
//Retrives Username and password from the Http Request
var hlbi = (HttpListenerBasicIdentity)context.User.Identity;
Console.WriteLine("Username: " + hlbi.Name);
Console.WriteLine("Password: " + hlbi.Password);
listener.Stop();`
但是我在互联网上发现的示例表明,大多数视图如下:
// view layer
foreach ($products as $key => $value) {
$str .= DisplayProductInfo($key);
}
function DisplayProductInfo($key)
{
echo '<div class="SubProjectCommentDetailInfo">';
$str = $this->controller->model->data[$key];
echo '</div>';
}
请提出正确的建议。
答案 0 :(得分:1)
发送数据数组以查看并遍历div