0

Estoy consumiendo un servicio de identificación de personas en PERÚ, y quiero realizar una consulta, pero hay un parámetro que me pide que ponga el nombre de un campo para que se pueda realizar la consulta. El campo que voy a usar será DNI, pero cómo lo implemento en el controlador, cómo le digo que al controlador que voy a usar un HTMLHelper de la vista?.

Vista Interesado

    @model wsCharlas.Models.ClsInteresado

@{
    ViewBag.Title = "CrearInteresado";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>CrearInteresado</h2>


@using (Html.BeginForm()) 
{
    @Html.AntiForgeryToken()

    <div class="form-horizontal">
        <h4>ClsInteresado</h4>
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        <div class="form-group">
            @Html.HiddenFor(model => model.ID_Inter, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.HiddenFor(model => model.ID_Inter, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.ID_Inter, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.dni_Inter, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.dni_Inter, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.dni_Inter, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.apePat_Inter, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.apePat_Inter, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.apePat_Inter, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.apeMat_Inter, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.apeMat_Inter, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.apeMat_Inter, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.nombres_Inter, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.nombres_Inter, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.nombres_Inter, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.fecha_nac_Inter, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.fecha_nac_Inter, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.fecha_nac_Inter, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.edad_Inter, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.edad_Inter, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.edad_Inter, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.sexo_Inter, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.sexo_Inter, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.sexo_Inter, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.correo_Inter, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.correo_Inter, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.correo_Inter, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.telefono_Inter, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.telefono_Inter, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.telefono_Inter, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.direccion_Inter, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.direccion_Inter, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.direccion_Inter, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.depar_Inter, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.depar_Inter, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.depar_Inter, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.provin_Inter, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.provin_Inter, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.provin_Inter, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.dist_Inter, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.dist_Inter, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.dist_Inter, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Create" class="btn btn-default" />
            </div>
        </div>
    </div>
}

    <div>
        @Html.ActionLink("Regresar", "MostraCharlas", null, new { @class = "btn btn-default" })
    </div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

Controlador Interesado

//Interesados
    public ActionResult CrearInteresado()
    {
        return View(new ClsInteresado());


    }

    [HttpPost]
    public ActionResult CrearInteresado(ClsInteresado interesado)
    {
        if (!ModelState.IsValid)
        {
            ViewBag.mensaje = "Datos Invalidos";
            return View(new ClsInteresado());
        }

        //-------

        if (Request.HttpMethod == "POST")
        {
            ServicesReniec.sConsultaDNISoapClient consultaDNI = new ServicesReniec.sConsultaDNISoapClient();
            List<string> resultado = new List<string>();
                                                       //AQUÍ SE DEBE COLOCAR EL CAMPO
            resultado = consultaDNI.Consulta("JVEGA",      txtDNI.Text);


        }

        //--------

        ViewBag.mensaje = "Datos Validos";

        ClsConexion con = new ClsConexion();
        var Cnx = con.Conexion();

        OracleCommand cmd = new OracleCommand("SIMEXA_SP_REGISTRAR_INTERESADO", Cnx);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.Add(new OracleParameter("param_DNI", OracleDbType.Varchar2)).Value = interesado.dni_Inter;
        cmd.Parameters.Add(new OracleParameter("param_Ape_pat", OracleDbType.Varchar2)).Value = interesado.apePat_Inter;
        cmd.Parameters.Add(new OracleParameter("param_Ape_mat", OracleDbType.Varchar2)).Value = interesado.apeMat_Inter;
        cmd.Parameters.Add(new OracleParameter("param_nombres", OracleDbType.Varchar2)).Value = interesado.nombres_Inter;
        cmd.Parameters.Add(new OracleParameter("param_fech_naci", OracleDbType.Varchar2)).Value = interesado.fecha_nac_Inter;
        cmd.Parameters.Add(new OracleParameter("param_edad", OracleDbType.Varchar2)).Value = interesado.edad_Inter;
        cmd.Parameters.Add(new OracleParameter("param_sexo", OracleDbType.Varchar2)).Value = interesado.sexo_Inter;
        cmd.Parameters.Add(new OracleParameter("param_correo", OracleDbType.Varchar2)).Value = interesado.correo_Inter;
        cmd.Parameters.Add(new OracleParameter("param_telefono", OracleDbType.Varchar2)).Value = interesado.telefono_Inter;
        cmd.Parameters.Add(new OracleParameter("param_direc", OracleDbType.Varchar2)).Value = interesado.direccion_Inter;
        cmd.Parameters.Add(new OracleParameter("param_dept", OracleDbType.Varchar2)).Value = interesado.depar_Inter;
        cmd.Parameters.Add(new OracleParameter("param_prov", OracleDbType.Varchar2)).Value = interesado.provin_Inter;
        cmd.Parameters.Add(new OracleParameter("param_dist", OracleDbType.Varchar2)).Value = interesado.dist_Inter;
        Cnx.Open();

        OracleTransaction tx = Cnx.BeginTransaction();
        cmd.ExecuteNonQuery();
        tx.Commit();

        Cnx.Close();
        cmd.Dispose();
        Cnx.Dispose();

        return View(interesado);
    }

1 respuesta 1

1

Si bien entiendo lo que necesitas entender es lo que se llama Enlace de Datos (Model Binding ó Data Binding) en Asp MVC. Aquí una referencia para Asp.Net Core, pero que aplica para todo MVC (https://docs.microsoft.com/es-es/aspnet/core/mvc/models/model-binding?view=aspnetcore-2.2)

Básicamente de lo que se trata es que para cada elemento html de entrada en tu forma, este será trasladado a alguna propiedad de la clase, por decirle de alguna manera. Si haces un post de tu forma, será a una propiedad c#, si haces un get entonces en el query string, etc.

En tu caso, lo que estas haciendo es genera un elemento html por cada HtmlHelper que tienes en tu vista. Al hacer el post de la forma, esos datos serán enviado a tu controlado y el Enlace de Datos hará su trabajo.

Para tu campo DNI, puedes usar el HtmlHelper de hidden, parecido a como tienes el de model.ID_Inter.

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.