views:

113

answers:

1

Hi all,

The replies in this post sound very convincing, however, this post is just over my head and was hoping for some help:

I have code in my partial view that looks like this:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>

<div class="messageBox1"></div>

<% Html.BeginForm("BusinessAdd", "Home", FormMethod.Post, new { id = "form1" }); %>

<label for="BusinessName">Business Name: </label>
<%= Html.TextBox("TxtBusinessName") %>
<a href="#" onclick="if ($('#form1').valid()) { $('#form1').submit(); } return false;">submit</a>

<script type="text/javascript">
    $("#form1").validate({
        errorLabelContainer: ".messageBox1",
        rules: {
            "TxtBusinessName": { required: true }
        },
        messages: {
            "TxtBusinessName": { required: "Required field" }
        }
    });
</script>
<% Html.EndForm(); %>

Thanks, rodchar

P.S. Will this question get seen or should I have posted a new question and referenced this post?

A: 

I don't think there is a problem with doing what you quoted above. I do it in my production mvc app. Sure if the volume of js you load onto the page after a full request gets massive then look for another option but if it's a couple of partials like this then it's fine.

Be practical. Don't over engineer. And try not to optimise early.

cottsak