您好,我需要在部分視圖中獲取Html前綴。如何在部分視圖中獲得HTMLPREFIX i剃刀
我有這樣的前綴連接的地方,我使我的部分觀點
Html.RenderPartial("Person", Model.Person, new ViewDataDictionary(Html.ViewDataContainer.ViewData)
{
TemplateInfo = new TemplateInfo { HtmlFieldPrefix = "DelegatePerson"}
});
現在,當我去到人PartialView 我需要的前綴,在這樣的情況下。
@Html.TextBoxFor(model => model.CPR, new { @class = "numericTextbox", maxlength = 10, id = "CprField", onkeyup ="CprFieldEdited("[HTMLPrefix]_FieldName");" })
但是我不知道該怎麼做。我現在一直在尋找很久。 我希望有人知道如何做到這一點或類似的東西。
編輯:
,這意味着我應該能夠告訴JavaScript函數CprFieldEdited的HTML前綴應該尋找在這種情況下,「DelegatePerson」
編輯2: 它似乎並不清楚我的意思,所以我會嘗試提供更多的代碼。
主頁:
//None relevant Code here
@Scripts.Render("~/bundles/person_search")
//None relevant Code here
<Body>
//None relevant Code here
Html.RenderPartial("Person", Model.Person, new ViewDataDictionary(Html.ViewDataContainer.ViewData)
{
TemplateInfo = new TemplateInfo { HtmlFieldPrefix = "DelegatePerson"}
});
//None relevant Code here
Html.RenderPartial("Person", Model.Person, new ViewDataDictionary(Html.ViewDataContainer.ViewData)
{
TemplateInfo = new TemplateInfo { HtmlFieldPrefix = "EmployerPerson"}
});
//None relevant Code here
</body>
在這種情況下,我得到了在同一個頁面上呈現相同類型的兩個局部模板
。然而,在他們內部,我需要告訴Javascript包,其中一個正在使用,因爲我不能使用ID,他們正在用於別的東西我的想法是什麼使用名稱屬性與前綴,但作爲下一個代碼顯示我可以「噸得到的JavaScript前綴它在這兩個分音之間區分
@Html.TextBoxFor(model => model.CPR, new {id = "CprField", onkeyup ="CprFieldEdited("[FieldNameWithPartialPrefix]");" })
問題是我不能給CprFieldEdited(‘[FieldNameWithPartialPrefix]’); javascript可以是「DelegatePerson_Fieldname」或「EmployerPerson」的「[FieldNameWithPartialPrefix]」
yes Javascript將需要前綴來區分主頁上的部分和主頁上另一部分的部分。 如果完全沒有意義 – Helbo
您不需要爲此傳遞'HtmlFieldPrefix'。只要做'ViewBag。CustomPrefix =「your_prefix」;' – rae1
啊現在我找到了解決方案你在哪裏@ rae1n我已經在主頁面中設置Viewbag並在部分頁面中使用它。這很簡單,我只是沒有意識到它。非常感謝。我會將你的答案標記爲最好的答案。 – Helbo