اذهب إلى المحتوى
  • 0

ماذا تعني HTML Helpers في MVC؟

OsamaSaif

السؤال

Recommended Posts

  • 1

تشبه HTML helpers في MVC العناصر (Controls) في  ASP.Net Wep Forms كالأزرار والقوائم المنسدلة ولكنها أكثر خفة ومرونة. على عكس عناصر Web Forms لا يحوي HTML helper على نموذج حدث event model ولا على حالة عرض view state.

تحوي MVC على الـ helpers القياسية للأنواع الأكثر شيوعًا من عناصر HTML مثل الوصلات links وعناصر النموذج HTML form مثل:

  • ()BeginForm
  • ()EndForm
  • ()TextArea
  • ()TextBox
  • ()CheckBox
  • ()RadioButton
  • ()ListBox
  • ()DropDownList
  • ()Hidden
  • ()Password

المثال التالي يوضح استخدام  ActionLink helper في MVC باستخدام Razor Syntax:

@Html.ActionLink("About this Website", "About")

استخدام ActionLink helper باستخدام ASP Syntax:

<%=Html.ActionLink("About this Website", "About")%>

يملك Html.ActionLink() عدّة خصائص منها:

.linkText    
.actionName    
.routeValues    
.controllerName    
.htmlAttributes    
.protocol    
.hostname    
.fragment

المثال أدناه يشرح استخدام معظم HTML helpers باستخدام ASP Syntax:

<%= Html.ValidationSummary("Create was unsuccessful. Please correct the errors and try again.") %>
<% using (Html.BeginForm()){%>
<p>
<label for="FirstName">First Name:</label>
<%= Html.TextBox("FirstName") %>
<%= Html.ValidationMessage("FirstName", "*") %>
</p>
<p>
<label for="LastName">Last Name:</label>
<%= Html.TextBox("LastName") %>
<%= Html.ValidationMessage("LastName", "*") %>
</p>
<p>
<label for="Password">Password:</label>
<%= Html.Password("Password") %>
<%= Html.ValidationMessage("Password", "*") %>
</p>
<p>
<label for="Password">Confirm Password:</label>
<%= Html.Password("ConfirmPassword") %>
<%= Html.ValidationMessage("ConfirmPassword", "*") %>
</p>
<p>
<label for="Profile">Profile:</label>
<%= Html.TextArea("Profile", new {cols=60, rows=10})%>
</p>
<p>
<%= Html.CheckBox("ReceiveNewsletter") %>
<label for="ReceiveNewsletter" style="display:inline">Receive Newsletter?</label>
</p>
<p>
<input type="submit" value="Register" />
</p>
<%}%>

 

تم التعديل في بواسطة Lujain
رابط هذا التعليق
شارك على الشبكات الإجتماعية

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...