このような単純な質問をして申し訳ありませんが、これを解決しようとして本当に長い時間を失いました。最後に、私はあなたに尋ねることにしました。
コードベースから始めましょう:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace Navigation.Helpers
{
public static class NavigationBarSE
{
public static MvcHtmlString RenderNavigationBarSE(this HtmlHelper helper, String[] includes)
{
return new MvcHtmlString("Y U no Work??");
//NavTypeSE res = new NavTypeSE(includes);
//String ress = res.toString();
//return new MvcHtmlString(ress);
}
}
}
元の形式では、このヘルパーは NavTypeSE クラスによって生成された文字列を返す必要があります。しかし、最終的に結果を得るために、私はそれが私のために文字列を返すことだけを望んでいます...しかし、それはしませんでした...
あなたが尋ねる前に、私はそれを言うことができます、
<add namespace="Navigation.Helpers"/>
ViewsフォルダーのWeb.configファイルに存在します。
詳細については、以下のように私の NavTypeSE クラス:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Navigation.Helpers
{
//Creates a Navigation Menu Type which includes Previous, Next and Validate Buttons
public class NavTypeSE
{
Boolean pr, nt, vld;
Boolean Previous { get; set; }
Boolean Next { get; set; }
Boolean Validate { get; set; }
public NavTypeSE(Boolean Previous, Boolean Next, Boolean Validate)
{
this.pr = Previous;
this.nt = Next;
this.vld = Validate;
}
public NavTypeSE() { }
public NavTypeSE(String[] inc)
{
for(int i=0; i<inc.Length; i++)//foreach (String s in inc)
{
String s = inc[i]; // Don't need for foreach method.
if (s.Equals("previous")||s.Equals("Previous"))
{
this.pr = true;
}
else if (s.Equals("next") || s.Equals("Next"))
{
this.nt = true;
}
else if (s.Equals("validate") || s.Equals("Validate"))
{
this.vld = true;
}
else
{
this.pr = false; this.nt = false; this.vld = false;
}
}
public String toString()
{
return "Previous: " + this.pr + ", Next: " + this.nt + ", Validate: " + this.vld;
}
}
}
また、私のビューでは、このヘルパーを以下のように呼び出します。
@{
String[] str = new String[] { "Previous", "next", "Validate" };
Html.RenderNavigationBarSE(str);
}
これは単なるプロジェクトのベースです。そして、私は C# と ASP.NET MVC プラットフォームの両方でスターター レベルです。お手間をおかけして申し訳ありません。