0
<div class="thumbnail" style="height: 70px; background-color: #EEEDED">
   <div style="font-weight: bold;font-size: 20px;text-align: center">
     @Html.Label(exam.ExamName,new{@style="cursor: pointer;color: #FF8627 "})
    </div> 
    <div style="font-size: 15px;text-align: center;color: #505050">
      @Html.Label("Total Tests: " + exam.TestInfoes.Count(), new{@style="cursor: pointer"})
   </div>
</div>

I have above HTML block, I want to put this whole block in tagin my mvc4 application. We can do it using maually writing whole block in between tag but I also want to pass some value in the link which will be created for tag

 <a href="~/Exam/SingleExam/" + some value from my model>

how do we do it ?

Also How can we achieve this using ActionLink ?

vaibhav shah
  • 4,939
  • 19
  • 58
  • 96

2 Answers2

0

You can do this by using Partials or Editor/Display Templates

To render the partial you can use:

@Html.RenderPartial("partialname", model); 

An article can be found here:

http://www.codeproject.com/Tips/617361/Partial-View-in-ASP-NET-MVC

To use templates you can use a custom defined Html.DisplayFor template.

There is an article about the subject here:

http://www.hanselman.com/blog/ASPNETMVCDisplayTemplateAndEditorTemplatesForEntityFrameworkDbGeographySpatialTypes.aspx

The main thing about the templates is that the template must mach the name of the class of the object.

With both methods you can pass your model.

I hope this helps.

Stefan
  • 17,448
  • 11
  • 60
  • 79
0

well I created link like this

<a href="~/Exam/SingleExam/@exam.Id">
  <div class="thumbnail" style="height: 70px; background-color: #EEEDED">
     <div style="font-weight: bold;font-size: 20px;text-align: center">
        @Html.Label(exam.ExamName,new{@style="cursor: pointer;color: #FF8627 "})
      </div> 
      <div style="font-size: 15px;text-align: center;color: #505050">
        @Html.Label("Total Tests: " + exam.TestInfoes.Count(), new{@style="cursor: pointer"})
      </div>
  </div>
</a>

Instead of using action link I just used html tag & passed id using @exam.id which created proper url for me.

vaibhav shah
  • 4,939
  • 19
  • 58
  • 96