Mvc报告模块带有单选按钮和搜索字段作为文本框 [英] Mvc report module with radio buttons and search field as textbox

查看:68
本文介绍了Mvc报告模块带有单选按钮和搜索字段作为文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对象参考null



控制器代码







在视图中调用页面时发生错误-----



////

Object reference null

Controller Code



Error occurs when calling the page in view at line-----

////

@Html.ValidationMessageFor(x => x.search_type)

///



我尝试了什么:



///

What I have tried:

<pre>   [Authorize]
        [HttpGet]
        public ActionResult ReportModule(string ac)
        {
            DbAccess da = new DbAccess();
            DisplayLndRep dn = new DisplayLndRep();
            LoginViewModel uinfo = new LoginViewModel();
            uinfo = TempData["UserInfo"] as LoginViewModel;
            lnd_prgm min_details = new lnd_prgm();
            dn.PageSize = 10;
            dn.LoginDetails = da.FindLoginDetails(User.Identity.Name);
            dn.FullName = da.FindUserInfoAD(User.Identity.Name).FullName;
            min_details = da.FindMeetingDetails(ac);
            if (min_details != null)
            {
                dn.FeedbackDetails = min_details;
            }
            //else
            //{               
            //    min_details.prgm_id = null;
            //    dn.FeedbackDetails = min_details;
            //}                   
            dn.FeedbackDetailList2 = da.FindAllMeetings();          
            return View(dn);
        }







Razor代码






Razor code

@using System.Web.Helpers
@model LndFeedbackReport.ViewModels.DisplayLndRep
@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@*<br />*@
<div class="row">
    <div class="panel panel-success" style="padding-top: 0px;">
        <div class="panel-heading">
            <span style="color:blue">Welcome</span>   <span style="color:black">User : </span><span style="color:red">@Model.FullName</span>      <span style="color:black">Salary Code : </span><span style="color:red">@Model.EmployeeId</span>      <span style="color:black">Designation : </span><span style="color:red">@Model.Designation</span>      <span style="color:black">Department : </span><span style="color:red"> @Model.DepartmentName </span>

        </div>
    </div>
</div>
<div>
    @if (TempData["notice"] != null)
    {
        <p class="alert alert-danger" id="successMessage">@TempData["notice"]</p>
    }
</div>
@if (@Model.FeedbackDetailList2.Count() > 0)
        {
    <div class="row">
        @*@using (Ajax.BeginForm("SearchItems", "Home", new AjaxOptions { HttpMethod = "Post", UpdateTargetId = "result" }))*@
        @using (Html.BeginForm("SearchRepItems", "Home", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form", enctype = "multipart/form-data" }))
                {
            @Html.AntiForgeryToken()
            @Html.ValidationSummary(false)
            @Html.HiddenFor(x => x.Lnd_Program.prgm_id)
            <div class="form-horizontal">
                <div class="form-group">
                    <span class="control-label col-md-3" style="font-weight:bold">Search items</span>
                    <div class="col-md-9 col-lg-9">
                        <div class="col-md-4 col-lg-4">
                            @Html.TextBoxFor(x => x.search_text, new { maxlength = "100", @class = "form-control", autocomplete = "off" })
                        </div>
                        <div class="col-md-8 col-lg-8">
                            @Html.RadioButtonFor(x => x.search_type, "0", new { @onchange = "ToggleInfo();" }) Individual.
                            @Html.RadioButtonFor(x => x.search_type, "1", new { @onchange = "ToggleInfo();" }) Training Institute.
                            @*@Html.RadioButtonFor(x => x.search_type, "2", false) Minute ID*@
                            @Html.ValidationMessageFor(x => x.search_type)
                        </div>
                    </div>
                </div>
                <div class="row col-md-12 pull-left">
                    <div class="form-group">
                        <div class="col-md-offset-5 col-md-12">

                            <button type="submit" id="NwSave" class="btn btn-info">Search</button>

                                <a class="btn btn-default" href="@Url.Action("Header", "Home", new { ac = @Model.Lnd_Program.prgm_id})">Reset</a>
                        </div>
                    </div>
                </div>
            </div>
                }
        
    </div>
        }
    <hr />
@*</div>*@
<hr />
<br />

<div class="wrap">
    <div class="content">
        @Html.AntiForgeryToken()
        <div class="inner-content" style="border:none">
            <span class="text-primary" style="color:crimson; font-size:larger">List of Feedback Submitted</span>

        </div>
    </div>
</div>
<br />
        </div>
    </div>
</div>

推荐答案

在您的代码中, x null?

In your code, is x null?
@Html.ValidationMessageFor(x => x.search_type)

可能是为了调用空对象属性。也许检查是否会有验证消息。试试这个,

It might be that the null object is being called for a property. Maybe check if there would be a validation message. Try this,

@if (!ViewData.ModelState.IsValid) {
   // Your code here.
}



这是你捕获它的方式之一验证消息,仅当它存在时。否则,你完全忽略该声明。


This is one of the ways in which you are capturing the validation message, only if it exists. Otherwise, you ignore that statement at all.


这篇关于Mvc报告模块带有单选按钮和搜索字段作为文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆