0

i have code in my controller (Maintenance) like this :

public JsonResult GetGroupPortfolioDetail(string sPFolioGroupCode)
    {
        var result = _portfolioRepository.GetGroupPortfolio(sPFolioGroupCode.Trim());
        var portfolio = new TPFolio();

        portfolio.PFolioCode = result.PortfolioGroupCode;
        portfolio.PFolioSName = result.ShortName;
        portfolio.PFolioFName = result.FullName;
        portfolio.ReportingCurrency = result.Curr;
        portfolio.NPWP = result.NPWP;
        portfolio.IsActive = result.IsActive; 

        return Json(portfolio, JsonRequestBehavior.AllowGet);
    }

and code in viewmodel (GroupPortfolioViewModel) :

public class GroupPortFolio
{

    public string PortfolioGroupCode { get; set; }
    public string PortfolioCode { get; set; }
    public string ShortName { get; set; }
    public string FullName { get; set; }
    public float Seq { get; set; }
    public string IsActive { get; set; }
    public string NPWP { get; set; }
    public string Curr { get; set; }
    public string TimestampID { get; set; }
}

and code for query in my repositories folder Name File : (portfolioRepository) :

public GroupPortFolio GetGroupPortfolio(string sPFolioGroupCode)
    {
        string query = "SELECT DISTINCT B.PFolioGroupCode AS PortfolioGroupCode, A.PFolioSName AS ShortName , A.PFolioFName AS FullName,  A.IsActive AS Active, A.ReportingCurrency AS Curr, A.NPWP AS NPWP, A.TimestampID AS TimestampID ";
        query = query + " FROM TPFolio As A INNER JOIN TPFolioGroup As B ON A.PFolioCode = B.PFolioGroupCode WHERE (B.PFolioGroupCode = '" + sPFolioGroupCode + "')";

        return _db.ExecuteQuery<GroupPortFolio>(query).SingleOrDefault();
    }

and code in View (GroupPortfolio) :

function loadGroupPortFolio(sPFolioGroupCode) {

    $.ajax({
        url: '@Url.Action("GetGroupPortfolioDetail", "Maintenance")',
        data: 'sPFolioGroupCode=' + sPFolioGroupCode,
        success: function (result) {
            $('#PortfolioGroupCode').val(result.PFolioCode);
            $('#PortfolioSName').val(result.PFolioSName);
            $('#PortfolioFName').val(result.PFolioFName);
            $('#Currency').val(result.ReportingCurrency);
            $('#NPWP').val(result.NPWP);
            var isactive = result.IsActive;
            $("input[name='RadioActive']").each(function () {
                if ($(this).val() == isactive) {
                    $(this).attr("checked", "checked");
                    //$(this).prop("checked", "checked");
                }
            });

            TimeStampIDPortfolio = result.TimestampID;
        }
    });
}

and html :

<fieldset>
                    <div class="row">
                        <section class="col col-lg-2">
                            <label class="label">Code</label>
                            <label class="input">
                                <input type="text" name="PortfolioCode" id="PortfolioGroupCode" />
                                <b class="tooltip tooltip-bottom-right">Portfolio Code</b>
                            </label>
                        </section>
                        <section class="col col-lg-2">
                            <label class="label">Short Name</label>
                            <label class="input">
                                <input type="text" name="PortfolioSName" id="PortfolioSName" />
                            </label>
                        </section>
                        <section class="col col-lg-2">
                            <label class="label">Full Name</label>
                            <label class="input">
                                <input type="text" name="PortfolioFName" id="PortfolioFName" />
                            </label>
                        </section>
                    </div>
                    <div class="row">
                        <section class="col col-lg-2">
                            <label class="label">Report Currency</label>
                            <label class="select">
                                @Html.DropDownListFor(model => model.Currency, Model.Currencies, new { @class = "input-sm" })
                                <i></i>
                            </label>
                        </section>
                        <section class="col col-lg-2">
                            <label class="label">NPWP</label>
                            <label class="input">
                                <input type="text" name="NPWP" id="NPWP" />
                            </label>
                        </section>
                        <section class="col col-lg-2">
                            <label class="label">Active</label>
                            <div class="inline-group">
                                <label class="radio">
                                    <input type="radio" name="RadioActive" class="RadioActive" value="T" />
                                    <i></i>
                                    Yes
                                </label>
                                <label class="radio">
                                    <input type="radio" name="RadioActive" class="RadioActive" value="F" />
                                    <i></i>
                                    No
                                </label>
                            </div>
                        </section>
                    </div>
                </fieldset>

and the question is i can't get the value from ' portfolio.IsActive ' in Controller. so when i run this in browser, the radio button for IsActive not checked. i get the value IsActive is Null. not T or F.

please help me, do you know what the mistake from my code ??

1 Answer 1

2

IsActive is null because your SQL query returns IsActive as Active:

SELECT DISTINCT B.PFolioGroupCode AS PortfolioGroupCode
              , A.PFolioSName AS ShortName 
              , A.PFolioFName AS FullName
              , A.IsActive AS Active /* <-- see here*/
              -- ...
FROM TPFolio As A ...

So either change your ViewModel from IsActive to Active or change the alias in you SQL query.

Plus: Use parameters! Think of little bobby tables.

Sign up to request clarification or add additional context in comments.

1 Comment

yes, you are right, thanx for your help, it solved now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.