在理想的"hello world"中,应该将强类型模型传递回视图.
return View(MyModel);
Run Code Online (Sandbox Code Playgroud)
如果事情变得棘手,我们可以创建一个
视图模型
return View(MyViewModel);
Run Code Online (Sandbox Code Playgroud)
恩.
MyViewModel
我可以避免创建整个ViewModel
并部分使用ViewBag.
ViewBag.Foo = Foo;
return View(MyModel);
Run Code Online (Sandbox Code Playgroud)
我意识到我会丢失一些强类型的功能
(例如Intellisense)
在我的ViewBag视图中.
这种做法是不是很草率?反对MVC代表什么?
如果是这样,ViewBag真正的意义何在?
当我使用
$("#FormEthernet").submit();
Run Code Online (Sandbox Code Playgroud)
表单已发布,操作在我的控制器中被命中,但没有数据传递,所有输入都为空.
(参数字典包含空条目...)
这是我的表格
@using (Html.BeginForm("MyAction", "MyController",FormMethod.Post, new { id = "FormEthernet",name="FormEthernet" }))
{
<div id="dialog-formEthernet" title="Update Ethernet Config">
<p class="validateTips">
All form fields are required.</p>
<fieldset>
<div>
Phone Number</div>
<div>
<input type="text" name="TNEthernet" id="TNEthernet" />
</div>
<div>
Up</div>
<div>
<input type="text" name="Up" id="Up" /></div>
<div>
Down</div>
<div>
<input type="text" name="Down" id="Down" /></div>
</fieldset>
</div>
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?JQUERY Bug?
这里更新是我的控制器
[HttpPost]
public ActionResult MyAction(string TNEthernet,string Up, string Down)
{
return RedirectToAction("MyOtherAction", new { id = TNEthernet });
}
Run Code Online (Sandbox Code Playgroud)
和一些提琴手(已发送)
POST …Run Code Online (Sandbox Code Playgroud) double Cost = 0.03;
var ttt = Cost.ToString("D3");
Run Code Online (Sandbox Code Playgroud)
和
System.FormatException:格式说明符无效.
为什么?
http://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.110).aspx#DFormatString
说没关系?
我在一个控制器中有2个动作
public ActionResult DoSomething()
{
...
}
public ActionResult SoSomethingAgain()
{
...
}
Run Code Online (Sandbox Code Playgroud)
我想两个请求都采取相同的行动.
也许是别名....
[ie. SoSomethingAgain]
public ActionResult DoSomething()
{
...
}
Run Code Online (Sandbox Code Playgroud)
什么是正确的方法?
我试图获取对文本框元素的引用,但 $el 未定义,而其 $ref 具有对象。
我在这里做错了什么......我过度简化了我的代码来提出这个问题。谢谢!
app.component('lit-entry', {
template:
/*html*/
`
<div>
{{ message }}
<input v-model="favoriteColor" type="textbox" ref="refColor" />
</div>
`,
data() {
return {
message :"Hey there!",
favoriteColor:"Blue"
}
}
, mounted() {
debugger;
var x = this.$refs.refColor.$el;
//refColor has a value but $el is undefined?!?
}
});
Run Code Online (Sandbox Code Playgroud) var regEx = new RegExp("/[0-9]/");
var test = 'TREE'
alert(test.match(regEx));
Run Code Online (Sandbox Code Playgroud)
或者
var regEx = new RegExp("/[0-9]/");
var test = '1234'
alert(test.match(regEx));
Run Code Online (Sandbox Code Playgroud)
为什么他们返回null?
我在这里错过了什么吗?
(好吧,昨晚的辩论让我精神耗尽)
当我想到一个时ViewBag,我把它与" 最后的发言权 " 联系起来.
这意味着您可以完成所有逻辑并将结果设置为它.
ViewBag.A = Some crazy math formula;
ViewBag.B = Another crazy math formula;
ViewBag.GrandTotal = Some crazy math formula + Another crazy math formula;
Run Code Online (Sandbox Code Playgroud)
这也有效:
ViewBag.A = Some crazy math formula;
ViewBag.B = Another crazy math formula;
ViewBag.GrandTotal = ViewBag.A + ViewBag.B;
Run Code Online (Sandbox Code Playgroud)
Yipes,我正在使用在运行时制定的变量!
无论如何这是荒谬的还是低效的?
a.Charge.Company.Name 是一个字符串,这是我的lambda表达式
var CompanyNameList = Prop.ChargeItems.SelectMany( a => a.Charge.Company.Name).ToList();
Run Code Online (Sandbox Code Playgroud)
然而CompanyNameList,List<char>不是List<string>...... 为什么?
我有一些对象列表
List<person>
person.firstname
Run Code Online (Sandbox Code Playgroud)
是一个属性
我想改成它
person.name
Run Code Online (Sandbox Code Playgroud)
怎么可以使用lambda表达式完成?
谢谢!
<span id="9460116557269599" onclick="getdata(6557269599,9460116557269599)"> More...</span>
function getdata(tn,x){
alert(x);
}
Run Code Online (Sandbox Code Playgroud)
为什么9460116557269600收到x.
它应该是9460116557269599.
我最近从源设备复制了一个功能齐全的网站
它不会建立.
一切似乎都存在,但我得到了
未知的服务器标签'asp:ScriptManager'和'asp:ListView'
我为这个项目运行3.5.(是的,我的服务器上也安装了该框架)
我错过了什么?
谢谢!
这可能看起来有点基本,但这是我第一次遇到这种连接方案.我正在尝试加入以下表格
表A
Apple
Banana
Run Code Online (Sandbox Code Playgroud)
表B
Blue
Red
Run Code Online (Sandbox Code Playgroud)
结果应该是:
Apple Blue
Apple Red
Banana Blue
Banana Red
Run Code Online (Sandbox Code Playgroud) List<int[]> A = ServiceItems.First()
.ServiceItemDetails.Select(x => new int[]{ x.Numbers}).ToList();
Run Code Online (Sandbox Code Playgroud)
这给我一个整数数组列表.
我需要一个普通整数列表
我试过这个:
List<int> A = ServiceItems.First()
.ServiceItemDetails.Select(x => new int{ x.Numbers})
.ToList();
Run Code Online (Sandbox Code Playgroud)
哎哟!
无法使用集合初始化类型int ....不实现IEnumerable
我如何实现这一目标以及到底发生了什么?
谢谢!
c# ×8
asp.net-mvc ×5
javascript ×2
lambda ×2
viewbag ×2
.net-3.5 ×1
jquery ×1
linq ×1
performance ×1
sql ×1
vue.js ×1
vuejs3 ×1