2016-07-29 6 views
-2

これは私のビューコードです。asp.netのモデルからページのタイトルを設定するには?

@model IEnumerable<TestApplication.Models.ApplicationUser> 

@{ 
    Layout = null; 
    ViewBag.Title = //what goes here? Model.FirstName? 
} 

<!DOCTYPE html> 

<html> 
<head> 
    <meta name="viewport" content="width=device-width" /> 
</head> 
<body> 
    <p> 
     @Html.ActionLink("Create New", "Create") 
    </p> 
    <table class="table"> 
     <tr> 
      <th> 
       @Html.DisplayNameFor(model => model.FirstName) 
      </th> 
     </tr> 

    @foreach (var item in Model) { 
     <tr> 
      <td> 
       @Html.DisplayFor(modelItem => item.FirstName) 
      </td> 
      <td> 
       @Html.ActionLink("Edit", "Edit", new { id=item.Id }) | 
       @Html.ActionLink("Details", "Details", new { id=item.Id }) | 
       @Html.ActionLink("Delete", "Delete", new { id=item.Id }) 
      </td> 
     </tr> 
    } 

    </table> 
</body> 
</html> 

私は姓がモデルにあるものにViewBagのタイトルを変更したいです。私はViewBag.Title = Model.FirstNameのようなものを期待しています。しかしそうしても、私は誤りがありました。では構文は何ですか?

ViewBag.Title = Model.First().FirstName; 

は、エラーがdisapearなければならないが、これは次のとおりです。

+0

どうしたらいいですか? –

+2

モデルは 'IEnumerable 'で、 'IEnumerable'はプロパティがありません。しかし、なぜ 'ApplicationUser'' FirstName'値の1つを ''の ''タグに割り当てようとしていますか? – <span class="text-secondary"> <small> <span></span> </small> </span> </p> </div> </div> </div> <div itemprop="comment" class="post-comment"> <div class="row"> <div class="col-lg-1"><span class="text-secondary">+0</span></div> <div class="col-lg-11"> <p class="commenttext">私はちょうどテストしていた。それはランダムなものだった。 – <span class="text-secondary"> <small> <span></span> </small> </span> </p> </div> </div> </div> </div> </div> </article> </div> <div class="answer-title"> <span class="text-logo margin-top-sm">A</span> <h2 class="title h4">答えて</h2> </div> <div class="item-description text-md markdown-body margin-bottom-40 voidso"> <article class="board-top-1 padding-top-10"> <div class="post-col vote-info"> <span class="count">0<i class="fa fa-thumbs-up"></i></span> <i class="fa fa-check fa-2x"></i> </div> <div class="post-offset"> <div class="answer fmt"> <p>問題は、あなたのモデルタイプ<code class="prettyprint-override">IEnumerable<TestApplication.Models.ApplicationUser></code>ので、あなたが呼び出すことはできませんの問題を実証するために<code class="prettyprint-override">ApplicationUser</code></p> <p>の財産であるということです、これを試してみてください正しい解決策ではありません。あなたは<em>と考えてください</em>あなたが表示したいユーザーのリストの中からファーストネーム</p> </div> <div class="post-info"> <div class="post-meta row"> <p class="text-secondary col-lg-6"> <span class="source"> <a rel="noopener" target="_blank" href="https://stackoverflow.com/q/38650115">出典</a> </span> </p> <p class="text-secondary col-lg-6"> <span class="float-right date"> <span>2016-07-29 03:35:42</span> </p> <p class="col-12"></p> <p class="col-12"></p></div> </div> <!-- comments --> <div class="comments"> <div itemprop="comment" class="post-comment"> <div class="row"> <div class="col-lg-1"><span class="text-secondary">+1</span></div> <div class="col-lg-11"> <p class="commenttext">同じ回答私は私を削除します:) – <span class="text-secondary"> <small> <a rel="noopener" target="_blank" href="https://stackoverflow.com/users/4827151/">Sherlock</a></span> <span></span> </small> </span> </p> </div> </div> </div> <div itemprop="comment" class="post-comment"> <div class="row"> <div class="col-lg-1"><span class="text-secondary">+0</span></div> <div class="col-lg-11"> <p class="commenttext">大いに感謝します – <span class="text-secondary"> <small> <span></span> </small> </span> </p> </div> </div> </div> <div itemprop="comment" class="post-comment"> <div class="row"> <div class="col-lg-1"><span class="text-secondary">+0</span></div> <div class="col-lg-11"> <p class="commenttext">私は 'Model.Select(x => x.FirstName).FirstOrDefault()'を 'Model.First()。FirstName'に使うことを好みます。結果がnullまたは空の場合、例外はスローされません。 – <span class="text-secondary"> <small> <span></span> </small> </span> </p> </div> </div> </div> </div> </div> </article> <div> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-6208739752673518" data-ad-slot="1038284119" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> </div> <div class="clearfix"> </div> <div class="relative-box"> <div class="relative">関連する問題</div> <ul class="relative_list"> <li> 1. <a href="http://ja.uwenku.com/question/p-orgnltpp-cm.html" target="_blank" title="UITableView内からタイトルを設定する"> UITableView内からタイトルを設定する </a> </li> <li> 2. <a href="http://ja.uwenku.com/question/p-pctxpitb-nc.html" target="_blank" title="NotificationManagerのタイトルを設定するには?"> NotificationManagerのタイトルを設定するには? </a> </li> <li> 3. <a href="http://ja.uwenku.com/question/p-oyrccvoc-ne.html" target="_blank" title="iframeからページのタイトルを取得して設定する方法"> iframeからページのタイトルを取得して設定する方法 </a> </li> <li> 4. <a href="http://ja.uwenku.com/question/p-mrmadveo-r.html" target="_blank" title="設定plistのタイトルを設定する"> 設定plistのタイトルを設定する </a> </li> <li> 5. <a href="http://ja.uwenku.com/question/p-dhffnzyc-hr.html" target="_blank" title="Joomlaコンポーネントの設定ページでタイトルを設定するにはどうすればよいですか?"> Joomlaコンポーネントの設定ページでタイトルを設定するにはどうすればよいですか? </a> </li> <li> 6. <a href="http://ja.uwenku.com/question/p-dyduhyvd-cs.html" target="_blank" title="ASP.NET MVC(剃刀)のモデルからjQueryプロパティを設定する方法"> ASP.NET MVC(剃刀)のモデルからjQueryプロパティを設定する方法 </a> </li> <li> 7. <a href="http://ja.uwenku.com/question/p-huuymhxs-eg.html" target="_blank" title="ASP.NET MVC - ドロップダウンリストに別のモデルを設定する方法"> ASP.NET MVC - ドロップダウンリストに別のモデルを設定する方法 </a> </li> <li> 8. <a href="http://ja.uwenku.com/question/p-khqknvdh-bv.html" target="_blank" title="IIS 6でASP.NETページを設定する"> IIS 6でASP.NETページを設定する </a> </li> <li> 9. <a href="http://ja.uwenku.com/question/p-hyasynmt-ch.html" target="_blank" title="asp.netページでタイマを設定する"> asp.netページでタイマを設定する </a> </li> <li> 10. <a href="http://ja.uwenku.com/question/p-xwnznqyn-dw.html" target="_blank" title="MFMailComposeViewControllerのタイトルをNILに設定する"> MFMailComposeViewControllerのタイトルをNILに設定する </a> </li> <div> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" style="display:block; text-align:center;" data-ad-layout="in-article" data-ad-format="fluid" data-ad-client="ca-pub-6208739752673518" data-ad-slot="4606349252"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> <li> 11. <a href="http://ja.uwenku.com/question/p-tgsdsdgg-gs.html" target="_blank" title="剣道グリッド(ASP.NET MVC) - DataTableバインドグリッドの列タイトルを設定します。"> 剣道グリッド(ASP.NET MVC) - DataTableバインドグリッドの列タイトルを設定します。 </a> </li> <li> 12. <a href="http://ja.uwenku.com/question/p-frotexyg-mb.html" target="_blank" title="asp.netのマスターページとaspxページにフォームタグを設定できますか?"> asp.netのマスターページとaspxページにフォームタグを設定できますか? </a> </li> <li> 13. <a href="http://ja.uwenku.com/question/p-yvwzytgd-cv.html" target="_blank" title="javascriptを使用してhtmlページのタイトルを設定します"> javascriptを使用してhtmlページのタイトルを設定します </a> </li> <li> 14. <a href="http://ja.uwenku.com/question/p-vasypvty-mr.html" target="_blank" title="URLに基​​づいたルートルートプロバイダの設定ページのタイトル"> URLに基​​づいたルートルートプロバイダの設定ページのタイトル </a> </li> <li> 15. <a href="http://ja.uwenku.com/question/p-hzmqnhja-co.html" target="_blank" title="ASP.Net Webフォーム - ページとユーザーコントロールからMasterPageのプロパティを設定する方法"> ASP.Net Webフォーム - ページとユーザーコントロールからMasterPageのプロパティを設定する方法 </a> </li> <li> 16. <a href="http://ja.uwenku.com/question/p-ubhajqbq-ex.html" target="_blank" title="msgboxのタイトルを設定しますか?"> msgboxのタイトルを設定しますか? </a> </li> <li> 17. <a href="http://ja.uwenku.com/question/p-gbsbmbuy-dn.html" target="_blank" title="古いクラシックASPページから新しいASP.NETウェブフォームページに301リダイレクトを設定する"> 古いクラシックASPページから新しいASP.NETウェブフォームページに301リダイレクトを設定する </a> </li> <li> 18. <a href="http://ja.uwenku.com/question/p-wqvjcpiu-nv.html" target="_blank" title="css django 1.11.xでモデルからイメージを設定するには?"> css django 1.11.xでモデルからイメージを設定するには? </a> </li> <li> 19. <a href="http://ja.uwenku.com/question/p-hnnfjcrk-nr.html" target="_blank" title="モデルから$ config ['sess_expiration'] codeigniterを設定するには?"> モデルから$ config ['sess_expiration'] codeigniterを設定するには? </a> </li> <li> 20. <a href="http://ja.uwenku.com/question/p-aebmfwtl-kk.html" target="_blank" title="ASP.NETのサーバー側のページ設定"> ASP.NETのサーバー側のページ設定 </a> </li> <li> 21. <a href="http://ja.uwenku.com/question/p-qzmvwwbt-cg.html" target="_blank" title="asp.net mvcでページ設定を作成するには"> asp.net mvcでページ設定を作成するには </a> </li> <li> 22. <a href="http://ja.uwenku.com/question/p-bddsmznz-dv.html" target="_blank" title="ASP.NET MVC - モデル決定:どのように設計するのですか?"> ASP.NET MVC - モデル決定:どのように設計するのですか? </a> </li> <li> 23. <a href="http://ja.uwenku.com/question/p-uiakqiwf-bm.html" target="_blank" title="iosのバックバーボタンアイテムのタイトルを設定する"> iosのバックバーボタンアイテムのタイトルを設定する </a> </li> <li> 24. <a href="http://ja.uwenku.com/question/p-vmfyceqz-et.html" target="_blank" title="asp.net:ページに複数のフォームを設定する"> asp.net:ページに複数のフォームを設定する </a> </li> <li> 25. <a href="http://ja.uwenku.com/question/p-tdrljrot-gc.html" target="_blank" title="がコンポーネントに反応 - ここで設定されたページのタイトル"> がコンポーネントに反応 - ここで設定されたページのタイトル </a> </li> <li> 26. <a href="http://ja.uwenku.com/question/p-tpxuthym-w.html" target="_blank" title="ASP.NetウィザードのサイドバーテンプレートのLinkBut​​tonタイトルの設定"> ASP.NetウィザードのサイドバーテンプレートのLinkBut​​tonタイトルの設定 </a> </li> <li> 27. <a href="http://ja.uwenku.com/question/p-hguvxrak-cp.html" target="_blank" title="モデルからのドロップダウンリストの設定値に直面する問題"> モデルからのドロップダウンリストの設定値に直面する問題 </a> </li> <li> 28. <a href="http://ja.uwenku.com/question/p-eyigmuei-pw.html" target="_blank" title="すべてのページのタイトルを表示するASP.NET MVC"> すべてのページのタイトルを表示するASP.NET MVC </a> </li> <li> 29. <a href="http://ja.uwenku.com/question/p-ndqttisy-eo.html" target="_blank" title="すべてのリクエストを設定ページにリダイレクトするAsp.net Mvcを設定するには?"> すべてのリクエストを設定ページにリダイレクトするAsp.net Mvcを設定するには? </a> </li> <li> 30. <a href="http://ja.uwenku.com/question/p-tliuafth-cx.html" target="_blank" title="Googleリーダーサブスクリプションのタイトルにリンクの場所を設定するには"> Googleリーダーサブスクリプションのタイトルにリンクの場所を設定するには </a> </li> </ul> </div> <div> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-6208739752673518" data-ad-slot="1575177025"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> <div class="padding-top-10"></div> </div> </div> <script type="text/javascript" src="http://img.uwenku.com/uwenku/script/side.js?t=1644592048742"></script> <script type="text/javascript" src="http://img.uwenku.com/uwenku/plugin/highlight/highlight.pack.js"></script> <link href="http://img.uwenku.com/uwenku/plugin/highlight/styles/docco.css" media="screen" rel="stylesheet" type="text/css" /> <script type="text/javascript"> $('pre').each(function(i, e) { hljs.highlightBlock(e, "<span class='indent'> </span>", false) }); </script> <div class="col-lg-3 col-md-4 col-sm-5"> <div id="rightTop"> <div class="row"> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-6208739752673518" data-ad-slot="5415218910" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> <div class="row sidebar panel panel-default"> <div class="panel-heading font-bold"> 最新の質問 </div> <div class="m-b-sm m-t-sm clearfix"> <ul class="side_article_list"> <li class="side_article_list_item"> 1. <a href="http://ja.uwenku.com/question/p-owauvpqh-ou.html" target="_blank" title="SFMLでの適切な衝突(C++)"> SFMLでの適切な衝突(C++) </a> </li> <li class="side_article_list_item"> 2. <a href="http://ja.uwenku.com/question/p-bnrjrnnb-ow.html" target="_blank" title="私のアプリをAIDEにインストールすると、なぜこのエラーがポップアップするのですか?"> 私のアプリをAIDEにインストールすると、なぜこのエラーがポップアップするのですか? </a> </li> <li class="side_article_list_item"> 3. <a href="http://ja.uwenku.com/question/p-obcfupwr-pw.html" target="_blank" title="plt.scatter(X [:50,0]、X [:50,1]、color = 'red'、マーカー= 'o'、ラベル= 'setosa')"> plt.scatter(X [:50,0]、X [:50,1]、color = 'red'、マーカー= 'o'、ラベル= 'setosa') </a> </li> <li class="side_article_list_item"> 4. <a href="http://ja.uwenku.com/question/p-xslfrofl-pv.html" target="_blank" title="Graphvizにネストされたノードシェイプを持つことは可能ですか?"> Graphvizにネストされたノードシェイプを持つことは可能ですか? </a> </li> <li class="side_article_list_item"> 5. <a href="http://ja.uwenku.com/question/p-nzkbcmbv-pt.html" target="_blank" title="htmlのサイズを縮小する方法を教えてください。"> htmlのサイズを縮小する方法を教えてください。 </a> </li> <li class="side_article_list_item"> 6. <a href="http://ja.uwenku.com/question/p-bkewnyqh-qd.html" target="_blank" title="MongooseでシードされたデータがMongoDBに保存されていません"> MongooseでシードされたデータがMongoDBに保存されていません </a> </li> <li class="side_article_list_item"> 7. <a href="http://ja.uwenku.com/question/p-esqvjxzy-qb.html" target="_blank" title="std :: initializer_listをメンバ変数として使用"> std :: initializer_listをメンバ変数として使用 </a> </li> <li class="side_article_list_item"> 8. <a href="http://ja.uwenku.com/question/p-ztvmqxir-od.html" target="_blank" title="バウンドバリアントジェネリックはAnyになりますか?"> バウンドバリアントジェネリックはAnyになりますか? </a> </li> <li class="side_article_list_item"> 9. <a href="http://ja.uwenku.com/question/p-ttjpepgs-ok.html" target="_blank" title="ビジュアルスタジオでdataGridViewセルをカスタマイズする方法"> ビジュアルスタジオでdataGridViewセルをカスタマイズする方法 </a> </li> <li class="side_article_list_item"> 10. <a href="http://ja.uwenku.com/question/p-pygzhzbw-oz.html" target="_blank" title="mysqlの注文方法は?"> mysqlの注文方法は? </a> </li> </ul> </div> </div> </div> <p class="article-nav-bar"></p> <div class="row sidebar article-nav"> <div class="row box_white visible-sm visible-md visible-lg margin-zero"> <div class="top"> <h3 class="title"><i class="glyphicon glyphicon-th-list"></i> 関連する問題</h3> </div> <div class="article-relative-content"> <ul class="side_article_list"> <li class="side_article_list_item"> 1. <a href="http://ja.uwenku.com/question/p-orgnltpp-cm.html" target="_blank" title="UITableView内からタイトルを設定する"> UITableView内からタイトルを設定する </a> </li> <li class="side_article_list_item"> 2. <a href="http://ja.uwenku.com/question/p-pctxpitb-nc.html" target="_blank" title="NotificationManagerのタイトルを設定するには?"> NotificationManagerのタイトルを設定するには? </a> </li> <li class="side_article_list_item"> 3. <a href="http://ja.uwenku.com/question/p-oyrccvoc-ne.html" target="_blank" title="iframeからページのタイトルを取得して設定する方法"> iframeからページのタイトルを取得して設定する方法 </a> </li> <li class="side_article_list_item"> 4. <a href="http://ja.uwenku.com/question/p-mrmadveo-r.html" target="_blank" title="設定plistのタイトルを設定する"> 設定plistのタイトルを設定する </a> </li> <li class="side_article_list_item"> 5. <a href="http://ja.uwenku.com/question/p-dhffnzyc-hr.html" target="_blank" title="Joomlaコンポーネントの設定ページでタイトルを設定するにはどうすればよいですか?"> Joomlaコンポーネントの設定ページでタイトルを設定するにはどうすればよいですか? </a> </li> <li class="side_article_list_item"> 6. <a href="http://ja.uwenku.com/question/p-dyduhyvd-cs.html" target="_blank" title="ASP.NET MVC(剃刀)のモデルからjQueryプロパティを設定する方法"> ASP.NET MVC(剃刀)のモデルからjQueryプロパティを設定する方法 </a> </li> <li class="side_article_list_item"> 7. <a href="http://ja.uwenku.com/question/p-huuymhxs-eg.html" target="_blank" title="ASP.NET MVC - ドロップダウンリストに別のモデルを設定する方法"> ASP.NET MVC - ドロップダウンリストに別のモデルを設定する方法 </a> </li> <li class="side_article_list_item"> 8. <a href="http://ja.uwenku.com/question/p-khqknvdh-bv.html" target="_blank" title="IIS 6でASP.NETページを設定する"> IIS 6でASP.NETページを設定する </a> </li> <li class="side_article_list_item"> 9. <a href="http://ja.uwenku.com/question/p-hyasynmt-ch.html" target="_blank" title="asp.netページでタイマを設定する"> asp.netページでタイマを設定する </a> </li> <li class="side_article_list_item"> 10. <a href="http://ja.uwenku.com/question/p-xwnznqyn-dw.html" target="_blank" title="MFMailComposeViewControllerのタイトルをNILに設定する"> MFMailComposeViewControllerのタイトルをNILに設定する </a> </li> </ul> </div> </div> </div> </div> </div> </div> </div><!-- wrap end--> <!-- footer --> <footer id="footer"> <div class="bg-simple lt"> <div class="container"> <div class="row padder-v m-t"> <div class="col-xs-8"> <ul class="list-inline"> <li><a href="http://ja.uwenku.com/contact">お問い合わせ</a></li> <li>© 2020 JA.UWENKU.COM</li> <li><a target="_blank" href="https://beian.miit.gov.cn/">沪ICP备13005482号-4</a></li> <li><script type="text/javascript" src="https://v1.cnzz.com/z_stat.php?id=1280101193&web_id=1280101193"></script></li> <li><a href="http://www.uwenku.com/" target="_blank" title="优文库">简体中文</a></li> <li><a href="http://hk.uwenku.com/" target="_blank" title="優文庫">繁體中文</a></li> <li><a href="http://ru.uwenku.com/" target="_blank" title="поле вопросов и ответов">Русский</a></li> <li><a href="http://de.uwenku.com/" target="_blank" title="Frage - und - antwort - Park">Deutsch</a></li> <li><a href="http://es.uwenku.com/" target="_blank" title="Preguntas y respuestas">Español</a></li> <li><a href="http://hi.uwenku.com/" target="_blank" title="कार्यक्रम प्रश्न और उत्तर पार्क">हिन्दी</a></li> <li><a href="http://it.uwenku.com/" target="_blank" title="IL Programma di chiedere Park">Italiano</a></li> <li><a href="http://ja.uwenku.com/" target="_blank" title="プログラム問答園区">日本語</a></li> <li><a href="http://ko.uwenku.com/" target="_blank" title="프로그램 문답 단지">한국어</a></li> <li><a href="http://pl.uwenku.com/" target="_blank" title="program o park">Polski</a></li> <li><a href="http://tr.uwenku.com/" target="_blank" title="Program soru ve cevap parkı">Türkçe</a></li> <li><a href="http://vi.uwenku.com/" target="_blank" title="Đáp ứng viên">Tiếng Việt</a></li> <li><a href="http://fr.uwenku.com/" target="_blank" title="Programme interrogation Park">Française</a></li> </ul> </div> </div> </div> </div> </div> </footer> <!-- / footer --> <script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?f78a970f17b19a79fc477a3378096f29"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> </body> </html>