TMan
TMan

Reputation: 4122

Using jquery plugin in MVC3

I'm using a jquery star rating plugin. Before I would just have a EditorFor Textbox and that would pass in the value of what ever the user would type but now I have 5 stars, how can pass the value of stars in my parameter. For example is i rate a teacher 4 stars, how can/would I pass that 4 in with everything else I'm submitting?

               @using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
    <legend>Teachers Ratings Wall</legend>

    <div class="editor-label">
        @Html.LabelFor(model => model.StarRating)
    </div>
    <div class="editor-field">
        @*@Html.EditorFor(model => model.StarRating)*@
        @Html.ValidationMessageFor(model => model.StarRating)
        <input name="star1" type="radio" class="star"/>
        <input name="star1" type="radio" class="star"/>
        <input name="star1" type="radio" class="star"/>
        <input name="star1" type="radio" class="star"/>
        <input name="star1" type="radio" class="star"/>
    </div>

    <div class="editor-label">
        @Html.LabelFor(model => model.PostComment)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.PostComment)
        @Html.ValidationMessageFor(model => model.PostComment)
    </div>

    <div class="editor-label">
        @Html.LabelFor(model => model.PostDate)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.PostDate)
        @Html.ValidationMessageFor(model => model.PostDate)
    </div>

    <div class="editor-label">
        @Html.LabelFor(model => model.Teacher)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.Teacher)
        @Html.ValidationMessageFor(model => model.Teacher)
    </div>


    <p>
        <input type="submit" value="Create" />
    </p>
</fieldset>

Upvotes: 1

Views: 738

Answers (1)

SLaks
SLaks

Reputation: 887877

You should move those <input>s into an EditorTemplate and set the names to @ViewData.TemplateInfo.GetFullHtmlFieldName("") and the values to 1 through 4.

Standard MVC model binding should handle the rest.

Upvotes: 2

Related Questions