我是新手 ASP.NET MVC 5,我正在尝试从表中获取数据并显示在文本框中。

huangapple go评论57阅读模式
英文:

I'm new to ASP NET MVC 5, I'm trying to get a data from a table and display it on a textbox

问题

I'm new to ASP.NET MVC. I'm trying to get the ITEMNAME from tbl_inventorycontrol.

@model RSMI.Models.Database.tbl_STOCKCARD

@Html.LabelFor(model => model.ITEMCODE, htmlAttributes: new { @class = "control-label col-md-2" })

@Html.EditorFor(model => model.ITEMCODE, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.ITEMCODE, "", new { @class = "text-danger" })

It should it should get the ITEMCODE value from tbl_stockcard. Then in stockcard controller, when I click search button, it should get the itemname in tbl_inventorycoller equal to the tbl_stockcard.ITEMCODE.

英文:

I'm new to ASP.NET MVC. I'm trying to get the ITEMNAME from tbl_inventorycontrol.

@model RSMI.Models.Database.tbl_STOCKCARD


@Html.LabelFor(model => model.ITEMCODE, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
    @Html.EditorFor(model => model.ITEMCODE, new { htmlAttributes = new { @class = "form-control" } })
    @Html.ValidationMessageFor(model => model.ITEMCODE, "", new { @class = "text-danger" })
    <br />
    <div class="form-group">
        <div class="col-md-offset-24 col-md-12">
            <input type="button" value="Search Item"  onclick="location.href='@Url.Action("SearchItemCode","Stockcard")'" class="btn btn-primary btn-block" />

It should it should get the ITEMCODE value from tbl_stockcard. Then in stockcard controller, when I click search button, it should get the itemname in tbl_inventorycoller equal to the tbl_stockcard.ITEMCODE.

我是新手 ASP.NET MVC 5,我正在尝试从表中获取数据并显示在文本框中。

答案1

得分: 1

以下是已翻译的内容:

"不太清楚您想要对筛选结果进行什么操作。看起来您的 return 语句不匹配。如果找到项目,您希望返回包含该项目的视图。请考虑以下方法:"

英文:

It's not entirely clear what you want to do with the filter result. Seems you mismatched you return statements. You want returning View with your item if found. Please consider this approach

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Searchitem(tbl_inventorycontrol tbl_Inventorycontrol )
{
    if (ModelState.IsValid)
    {   
        var item = db.tbl_inventorycontrol.Where(tbl_STOCKCARD => tbl_STOCKCARD.ITEMCODE == tbl_Inventorycontrol.SUPPLIES).FirstOrDefault();
        
        if (item != null)
        {
            return View(item);
        }    
    }
    return View(tbl_Inventorycontrol);
}

huangapple
  • 本文由 发表于 2023年5月17日 14:51:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/76269258.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定