2012-06-04 5 views
0

J'ai un système fait en MVC3 (VB.NET) et c'est très bien. J'essaye de mettre à jour ce système à MVC4 (bêta), et tout fonctionne bien sauf HttpPost.MVC4 HttpPost ne pas tirer

Voici le code de la vue (rasoir):

@Using Html.BeginForm() 

    @<fieldset> 
     <legend></legend> 
     <br /> 

     <fieldset> 
      <legend>Datos Generales</legend> 
      <table> 
       <tr> 
        <td style="border-width:0px; border-style:solid"> 
         @Html.LabelFor(Function(Model) Model.IDCertificado) 
         @Html.TextBox("ID_CERTIFICADO1", "Automático", New With {.readonly = "readonly", .style = "width:90px; text-align:center", .class = "letraingreso"}) 
        </td> 
        <td style="width:20px"></td> 
        <td style="border-width:0px; border-style:solid"> 
         @Html.LabelFor(Function(Model) Model.IDPoliza) 
         @Html.DropDownListFor(Function(Model) Model.IDPoliza, Nothing, New With {.style = "width:200px; visibility:visible", .class = "letraingreso"}) 
        </td> 
       </tr> 
       <tr> 
        <td style="border-width:0px; border-style:solid"> 
         @Html.LabelFor(Function(Model) Model.IDCampaña) 
         @Html.DropDownListFor(Function(Model) Model.IDCampaña, Nothing, New With {.style = "width:250px; visibility:visible", .class = "letraingreso"}) 
        </td> 
        <td style="width:20px"></td> 
        <td style="border-width:0px; border-style:solid"> 
         @Html.LabelFor(Function(Model) Model.IDVigencia) 
         @Html.DropDownListFor(Function(Model) Model.IDVigencia, Nothing, New With {.style = "width:183px; visibility:visible", .class = "letraingreso", .disabled = "disabled"}) 
        </td> 
       </tr> 
      </table> 
     </fieldset> 
     <br /> 

     <fieldset> 
      <legend>Datos del Certificado</legend> 
      <table width="99%"> 
       <tr> 
        <td style="border-width:0px; border-style:solid; width:8%"> 
         @Html.LabelFor(Function(Model) Model.FechaEmision) 
        </td> 
        <td style="border-width:0px; border-style:solid; width:11%"> 
         @Html.TextBox("FechaEmision", Nothing, New With {.style = "width:80px; text-align:center", .class = "letraingreso", .readonly = "readonly"}) 
        </td> 
        <td style="width:1%"></td> 
        <td style="border-width:0px; border-style:solid; width:8%"> 
         @Html.LabelFor(Function(Model) Model.FechaInicioVigencia) 
        </td> 
        <td style="border-width:0px; border-style:solid; width:12%"> 
         @Html.TextBoxFor(Function(Model) Model.FechaInicioVigencia, New With {.maxLength = "10", .onkeyup = "DateFormat(this, this.value, event, false, '3')", .onblur = "DateFormat(this, this.value, event, true, '3')", .style = "width:80px", .class = "letraingreso"}) 
         <a href="#"><img src="@Url.Content("~/Images/spacer.gif")" class="imagenfecha" style="border:0" height="16px" width="20px" id="imgFechaInicioVigencia" alt="" /></a> 
         <script type="text/javascript"> 
          Calendar.setup(
          { 
           inputField: "FechaInicioVigencia", 
           ifFormat: "%d/%m/%Y", 
           button: "imgFechaInicioVigencia", 
           align: "Tl", 
           singleClick: true 
          }); 
         </script> 
        </td> 
        <td style="width:1%"></td> 
        <td style="border-width:0px; border-style:solid; width:25%"> 
         @Html.LabelFor(Function(Model) Model.FechaFinVigencia) 
         @Html.TextBoxFor(Function(Model) Model.FechaFinVigencia, New With {.maxLength = "10", .onkeyup = "DateFormat(this, this.value, event, false, '3')", .onblur = "DateFormat(this, this.value, event, true, '3')", .style = "width:80px", .class = "letraingreso"}) 
         <a href="#"><img src="@Url.Content("~/Images/spacer.gif")" class="imagenfecha" style="border:0" height="16px" width="20px" id="imgFechaFinVigencia" alt="" /></a> 
         <script type="text/javascript"> 
          Calendar.setup(
          { 
           inputField: "FechaFinVigencia", 
           ifFormat: "%d/%m/%Y", 
           button: "imgFechaFinVigencia", 
           align: "Tl", 
           singleClick: true 
          }); 
         </script> 
        </td> 
       </tr> 

       <tr> 
        <td style="border-width:0px; border-style:solid; width:8%"> 
         @Html.LabelFor(Function(Model) Model.IDEstado) 
        </td> 
        <td style="border-width:0px; border-style:solid; width:11%"> 
         @Html.DropDownListFor(Function(Model) Model.IDEstado, Nothing, New With {.style = "width:100px; visibility:visible", .class = "letraingreso", .disabled = "disabled"}) 
        </td> 
        <td style="width:1%"></td> 
        <td colspan="5" style="border-width:0px; border-style:solid; width:13%"> 
         @Html.LabelFor(Function(Model) Model.IDPlanGrupoCobertura) 
         @Html.DropDownListFor(Function(Model) Model.IDPlanGrupoCobertura, Nothing, New With {.style = "width:350px; visibility:visible", .class = "letraingreso"}) 
        </td> 
       </tr> 
      </table> 
     </fieldset> 
     <br /> 

     <div id="tabs"> 
      @*Establece los tabs a ser creados*@ 
      <ul> 
       <li><a href="#fragment-1"><span>Asegurado</span></a></li> 
      </ul> 

      @*Asegurados*@ 
      <div id="fragment-1"> 
       <table> 
        <tr> 
         <td style="border-width:0px; border-style:solid; width:58px"> 
          @Html.LabelFor(Function(Model) Model.IDAsegurado) 
         </td> 
         <td style="border-width:0px; border-style:solid"> 
          @Html.TextBox("IDAsegurado", "Automático", New With {.readonly = "readonly", .style = "width:80px; text-align:center", .class = "letraingreso"}) 
         </td> 
         <td style="width:10px"></td> 
         <td style="border-width:0px; border-style:solid"> 
          @Html.LabelFor(Function(Model) Model.IDTipoDocumentoAsegurado) 
          @Html.DropDownListFor(Function(Model) Model.IDTipoDocumentoAsegurado, Nothing, New With {.style = "width:200px; visibility:visible", .class = "letraingreso"}) 
         </td> 
         <td style="width:10px"></td> 
         <td style="border-width:0px; border-style:solid"> 
          @Html.LabelFor(Function(Model) Model.NumeroDocumentoAsegurado) 
          @Html.TextBoxFor(Function(Model) Model.NumeroDocumentoAsegurado, New With {.onkeyup = "if(this.value.match(/\D/))this.value=this.value.replace(/\D/g,'')", .class = "letraingreso", .style = "width:100px"}) 
         </td> 
         <td style="width:10px"></td> 
         <td style="border-width:0px; border-style:solid"> 
          @Html.LabelFor(Function(Model) Model.FechaNacimientoAsegurado) 
          @Html.TextBoxFor(Function(Model) Model.FechaNacimientoAsegurado, New With {.maxLength = "10", .onkeyup = "DateFormat(this, this.value, event, false, '3')", .onblur = "DateFormat(this, this.value, event, true, '3')", .style = "width:80px", .class = "letraingreso"}) 
          <a href="#"><img src="@Url.Content("~/Images/spacer.gif")" class="imagenfecha" style="border:0" height="16px" width="20px" id="imgFechaNacimientoAsegurado" alt="" /></a> 
          <script type="text/javascript"> 
           Calendar.setup(
           { 
            inputField: "FechaNacimientoAsegurado", 
            ifFormat: "%d/%m/%Y", 
            button: "imgFechaNacimientoAsegurado", 
            align: "Tl", 
            singleClick: true 
           }); 
          </script> 
         </td> 
        </tr> 
       </table> 
       <table> 
        <tr> 
         <td style="border-width:0px; border-style:solid; width:58px"> 
          @Html.LabelFor(Function(Model) Model.NombresAsegurado) 
         </td> 
         <td style="border-width:0px; border-style:solid"> 
          @Html.TextBoxFor(Function(Moel) Model.NombresAsegurado, New With {.style = "text-transform:uppercase; width:270px", .class = "letraingreso"}) 
         </td> 
         <td style="width:15px"></td> 
         <td style="border-width:0px; border-style:solid"> 
          @Html.LabelFor(Function(Model) Model.PrimerApellidoAsegurado) 
          @Html.TextBoxFor(Function(Model) Model.PrimerApellidoAsegurado, New With {.style = "text-transform:uppercase; width:182px", .class = "letraingreso"}) 
         </td> 
         <td style="width:15px"></td> 
         <td style="border-width:0px; border-style:solid"> 
          @Html.LabelFor(Function(Model) Model.SegundoApellidoAsegurado) 
          @Html.TextBoxFor(Function(Model) Model.SegundoApellidoAsegurado, New With {.style = "text-transform:uppercase; width:182px", .class = "letraingreso"}) 
         </td> 
        </tr> 
       </table> 
       <table> 
        <tr> 
         <td style="border-width:0px; border-style:solid; width:58px"> 
          @Html.LabelFor(Function(Model) Model.IDCiudadAsegurado) 
         </td> 
         <td style="border-width:0px; border-style:solid"> 
          @Html.DropDownListFor(Function(Model) Model.IDCiudadAsegurado, Nothing, New With {.style = "width:180px; visibility:visible", .class = "letraingreso"}) 
         </td> 
         <td style="width:15px"></td> 

         <td style="border-width:0px; border-style:solid"> 
          @Html.LabelFor(Function(Model) Model.IDGeneroAsegurado) 
          @Html.DropDownListFor(Function(Model) Model.IDGeneroAsegurado, Nothing, New With {.style = "width:98px; visibility:visible", .class = "letraingreso"}) 
         </td> 
        </tr> 
       </table> 
      </div> 

     </div> 

     <br /> 
     <fieldset> 
      <legend>Observaciones</legend> 
      @Html.LabelFor(Function(Model) Model.Observaciones) 
      @Html.TextBoxFor(Function(Model) Model.Observaciones, New With {.class = "letraingreso", .style = "width:90%; text-transform:uppercase"}) 
     </fieldset> 
    </fieldset> 

    @<div style="display:none; position:absolute; margin:auto; left:0; right:0; text-align:center" id="inprogress"> 
     <br /><br /><br /><br /><br /><br /> 
     <img id="inprogress_img" src="@Url.Content("~/Images/loading.gif")" alt="Procesando..." /> 
     <br /> 
     Por favor espere mientras su solicitud es procesada... 
    </div> 

    @<p> 
     <input type="submit" value="Guardar" id="cmdGuardar" onclick="return doSubmit()" /> 
    </p> 

    @<div> 
     @Html.ActionLink(" ", "ListarCertificadosAPG", "CertificadosLayout", New With {.area = ""}, New With {.class = "imgRegresar", .title = "Regresar"}) 
    </div> 
End Using 

Comme je l'ai dit, en MVC3, soumettre le bouton raise contrôleur:

<HttpPost()> _ 
    Function Create(<Bind(Exclude:="IDCertificado, IDAsegurado")> ByVal parCertificadoAPG As Global.iSAM.Certificados) As ActionResult 

todo End Function

Mais MVC4 pas tir HttpPost. Je mets le code suivant (comme exemple) après End Using dans le code de la vue:

@Using Html.BeginForm() 
    @<input type="submit" value="SSS" /> 
End Using 

Et quand je presse bouton SSS il ressuscite les HttpPost. Quelqu'un peut-il m'aider à résoudre ou à comprendre où est l'erreur ou l'erreur?

Cordialement.

+0

Dans votre premier exemple, l'événement de clic du bouton de soumission est remplacé par JS. Pouvez-vous poster le code de la fonction 'doSubmit()'? – nemesv

Répondre

1

Après quelques tests, j'ai trouvé la raison pour laquelle soumettre ne se lève pas. Sur mon MainLayout j'ai déclaré:

<script src="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl("~/Scripts/js")"></script> 

Je devais commenter cette ligne et soumettre des travaux. Cependant, je ne sais pas pourquoi cette ligne fait soumettre ne fonctionne pas.

J'ai installé MVC4 RC et maintenant j'ai commenté ces 3 lignes:

<link href="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl("~/Content/css")" rel="stylesheet" type="text/css" /> 
<link href="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl("~/Content/themes/base/css")" rel="stylesheet" type="text/css" /> 
<script src="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl("~/Scripts/js")"></script> 

j'ai besoin d'examiner plus profondément MVC4 de savoir ce que font thease lignes. Cordialement à tous.

+0

J'ai le même problème. Cependant, je ne vois pas les lignes ci-dessus dans mon code. Après avoir commenté '@ scripts.Render (" ~/bundles/jqueryval ")', le HttpPost fonctionne pour moi. Je dois rechercher plus pourquoi cette ligne cause le problème. Je vous remercie! – rk1962