0

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?

Community
  • 1
  • 1
Rod
  • 14,529
  • 31
  • 118
  • 230
  • 1
    Perhaps rephrase the question to address specifically the elements that were "over your head" in the referenced post. – Matt Sep 14 '09 at 21:10
  • The reply said: "If you are going through the hassle of including javascript in your partial views, I would switch to just returning JSON in your ajax calls, that way you can handle it all on the client." I have javascript in my partial view so should I use JSON instead? How? – Rod Sep 15 '09 at 13:27

1 Answers1

0

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.

Matt Kocaj
  • 11,278
  • 6
  • 51
  • 79